I have a question when calling fsolve() in the program. When calling from cas screen, we can use fsolve() with the following:
fsolve(<equation>, <variable>)
For example, fsolve(sin(x)/x = 0, x)
When calling from program, what is the data type of <equation>, <variable>. I tried string, it doesn’t work.
Any idea about this?
When working with CAS commands in ppl, use the CAS command with quoted content, like this:
Code:
EXPORT temp()
BEGIN
LOCAL x,y;
CAS.fsolve("[x^2+y-2,x+y^2-2],[x,y],[0,0]");
END;
@DrD, thank you very much for your help. For the command you provided, it works.
However, if I write the code like this:
Code:
EXPORT temp()
BEGIN
LOCAL x,y;
LOCAL equn;
equn := “[x^2+y-2,x+y^2-2],[x,y],[0,0]”;
RETURN CAS.fsolve(equn);
END;
It doesn’t work. It just return fsolve(equn). How can we have fsolve() or CAS.fsolve() accept the input from string variable?
Try:
EXPORT temp()
BEGIN
// LOCAL x,y;
LOCAL equn;
equn:="[x^2+y-2,x+y^2-2],[x,y],[0,0]";
RETURN CAS.fsolve(EVAL(equn));
END;
-road
Thank you, roadrunner. That’s work! Why do we need to remove declaration of x, y variable?
I was getting this error message when I used local variables:
"fsolve([equations],[variables],[guesses]) Error: Bad Argument Value"
I may be wrong, but I think when you call a CAS command from a program with local variables it used the value stored in the variable so it was really trying to do this:
fsolve([0^2+0-2,0+0^2-2],[0,0],[0,0])
which generated that error message. It's best to use undefined variables for fsolve.
-road
ok. got the point. thank you
(07-01-2019 07:17 PM)teerasak Wrote: [ -> ]Thank you, roadrunner. That’s work! Why do we need to remove declaration of x, y variable?
You can make the variables local to the entire scope of the program:
Code:
LOCAL x,y;
EXPORT temp()
BEGIN
// LOCAL x,y;
LOCAL equn;
equn:="[x^2+y-2,x+y^2-2],[x,y],[0,0]";
RETURN CAS.fsolve(EVAL(equn));
END;