Post Reply 
Differences in Home vs CAS
10-19-2022, 08:55 PM (This post was last modified: 10-20-2022 01:22 AM by ftneek.)
Post: #1
Differences in Home vs CAS
Hello, I'm fairly new to the HP Prime and PPL. I started out by trying to recreate a program I wrote in python as a CAS program, but was running into some problems. After a few days of debugging and writing it as a non-CAS program, it works as I'm expecting in the home view, but when I run it in the CAS view it generates warnings that "A/B with B a square matrix is misleading notation interpreted as inv(B)*A", and error "Ifte: Unable to check test Error: Bad Argument Value". Can someone help me understand why that is? Are matrix calculations treated differently in Home vs CAS mode? Ideally I would like my program to works in both modes, with decimals returned in home view and fractions in CAS. I have also tried using the syntax for a cas program but then it errors in either mode. I would appreciate any insights or suggestions.

For reference it is the iterative conjugate gradient method to solve Ax=b, where in this case A is the nxn Hilbert matrix and b is an nx1 matrix which is the rowsum of A, so the exact solution for x is an nx1 matrix composed of 1's, but the computed solution should be "close" to 1's.

Code:
EXPORT conjugate_gradient(A, b)
BEGIN

LOCAL x, t, r, I, n;

n := DIM(A);
x := MAKEMAT(0, n(1), 1);
x(1, 1) := 1;
I := 1;
r := A*x - b;

WHILE I < 75 DO
t := (TRN(r)*r) / (TRN(r)*A*r);
x := x - r*t;
r := A*x - b;
IF ROWNORM(r) < .001 THEN
BREAK;
END;
I := I + 1;
END;

RETURN {I, x};
END;

Here is also a method for generating the rowsum, since I couldn't find an easy way to that with any of the built in methods. It works in both CAS and home view.

Code:
#cas
rowsum(A):=
BEGIN

LOCAL n;
LOCAL b;
LOCAL I;

n := dim(A);
b := makemat(0, n(1), 1);

FOR I FROM 1 TO n(1) DO
b(I,1) += ΣLIST(row(A, I));
END;

RETURN b;

END;
#end

update: So after some more digging, I think it those warnings came from a leftover file from when I was writing it as a CAS program. I reset my virtual calculator and retransferred the files. It works in Home mode but when I call
Code:
conjugate_gradient(hilbert(20), rowsum(hilbert(20)))
in CAS mode I no longer get the previous warnings, instead I get this error: "Error: Bad argument type". Why is that? I would like the conjugate_gradient method to work in CAS mode if possible. My question still stands if there are differences between how matrix calculations are performed in CAS mode. Thank you
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Differences in Home vs CAS - ftneek - 10-19-2022 08:55 PM
RE: Differences in Home vs CAS - parisse - 10-20-2022, 05:56 AM
RE: Differences in Home vs CAS - ftneek - 10-21-2022, 12:42 AM
RE: Differences in Home vs CAS - parisse - 10-21-2022, 10:02 AM
RE: Differences in Home vs CAS - ftneek - 10-21-2022, 03:00 PM
RE: Differences in Home vs CAS - parisse - 10-21-2022, 03:52 PM
RE: Differences in Home vs CAS - ftneek - 10-21-2022, 05:43 PM



User(s) browsing this thread: 1 Guest(s)