Post Reply 
Program returns String - how to fix
02-22-2023, 06:05 AM
Post: #1
Program returns String - how to fix
Have a look at this program:

ZIN_F:=4000000;
ZIN_REAL:=400;
ZIN_IMA:=400;

EXPORT ZIN()
BEGIN
LOCAL REAL,IMA,n,w;
LOCAL x,y,z;
INPUT({{ZIN_F,[0]},{ZIN_REAL,[0]},{ZIN_IMA,[0]}},"IMPEDANCE",{"freq","real","imag"});

w:=2*π*ZIN_F;
n:="1+"+w^2+"*r^2*c^2";
x:="[r/("+n+")="+ZIN_REAL+","+w+"*c*r^2/("+n+")="+ZIN_IMA+"]";
y:="[r,c]";
z:=CAS.solve(EVAL(x),EVAL(y));

RETURN z(1);
END;


It returns a String like "solve([(........" and does not really try to solve.

Years ago I bought myself a prime with the intention to learn how to properly use it. This is one of the old programs I tried to write during that time and I have to admit I am not 100% sure if it ever worked as inteded - I think it is clear what I want to achieve.

Can someone point out what I am doing wrong? Thanks in advance.

sincerely Hape
Find all posts by this user
Quote this message in a reply
02-22-2023, 06:20 PM (This post was last modified: 02-22-2023 06:21 PM by roadrunner.)
Post: #2
RE: Program returns String - how to fix
I think it's a bug in the firmware because in cas this:

solve([(r/(1+6*r^2*c^2)) = 400,(2*c*r^2/(1+6*r^2*c^2)) = 400],[r,c])

returns this for an answer:

{[1000,1/2000]}

but this:

solve([(r/(1+6*r^2*c^2)) = 400,(2*c*r^2/(1.+6*r^2*c^2)) = 400],[r,c])

causes a bad arg value error and returns this string:

["solve([(r/(1+6*r^2*c^2)) = 400,(2*c*r^2/(1.0+6*r^2*c^2)) = 400],[r,c])
Error: Bad Argument Value"]

The only difference is that I added a desimal point after the 1 in the second equation. fsolve and csolve do the same thing. Perhaps someone with access to the bug tracker can check to see if this is a known bug or not.

-road
Find all posts by this user
Quote this message in a reply
02-22-2023, 06:39 PM (This post was last modified: 02-22-2023 06:46 PM by roadrunner.)
Post: #3
RE: Program returns String - how to fix
Anyway, about your program, if you convert everything to exact it works:

Code:
ZIN_F:=4000000;
ZIN_REAL:=400;
ZIN_IMA:=400;

EXPORT ZIN()
BEGIN
LOCAL REAL,IMA,n,w;
LOCAL x,y,z;
INPUT({{ZIN_F,[0]},{ZIN_REAL,[0]},{ZIN_IMA,[0]}},"IMPEDANCE",{"freq","real","imag"});

w:=exact(2*π*ZIN_F);
n:="1+"+exact(w^2)+"*r^2*c^2";
x:="[r/("+exact(n)+")="+exact(ZIN_REAL)+","+exact(w)+"*c*r^2/("+exact(n)+")="+exact(ZIN_IMA)+"]";
y:="[r,c]";

z:=CAS.solve(EVAL(x),EVAL(y));

RETURN z(1);
END;

-road
Find all posts by this user
Quote this message in a reply
Post Reply 




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