Program returns String - how to fix
02-22-2023, 06:05 AM
Post: #1
 hape Junior Member Posts: 13 Joined: Feb 2014
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
Post: #2
 roadrunner Senior Member Posts: 443 Joined: Jun 2015
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])

{[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])

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.

Post: #3
 roadrunner Senior Member Posts: 443 Joined: Jun 2015
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;