HP Forums
Input data type for fsolve() for PPL - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Input data type for fsolve() for PPL (/thread-13203.html)



Input data type for fsolve() for PPL - teerasak - 06-29-2019 12:27 PM

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?


RE: Input data type for fsolve() for PPL - DrD - 06-29-2019 03:26 PM

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;



RE: Input data type for fsolve() for PPL - teerasak - 06-29-2019 05:48 PM

@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?


RE: Input data type for fsolve() for PPL - roadrunner - 06-30-2019 05:15 PM

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


RE: Input data type for fsolve() for PPL - teerasak - 07-01-2019 07:17 PM

Thank you, roadrunner. That’s work! Why do we need to remove declaration of x, y variable?


RE: Input data type for fsolve() for PPL - roadrunner - 07-02-2019 11:48 AM

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


RE: Input data type for fsolve() for PPL - teerasak - 07-02-2019 01:21 PM

ok. got the point. thank you


RE: Input data type for fsolve() for PPL - DrD - 07-02-2019 07:11 PM

(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;