# HP Forums

Full Version: HP Prime: What's wrong with this program?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Anyone have an idea why I keep getting a syntax error with:

EXPORT Solver(a,b,c)
BEGIN

RETURN solve(a*x*x+b+x+c=0,x);

END;

Other things I've tried:

RETURN "solve(a*x*x+b+x+c=0,x)";
RETURN CAS.solve(a*x*x+b+x+c=0,x);
RETURN "CAS.solve(a*x*x+b+x+c=0,x)";
RETURN solve(a*x*x+b+x+c=0);

and many variations of uppercase and lowercase variables, etc.

TIA, Bruce

Hello,

At the root cause of the problem is the fact that the CAS does not have access to your local variables. Basicaly, we did everything we could to have the CAS and the numeric world as integrated as possible, however, local variable is something that we did not manage to do 100%

Yours is a case where that fact pops up to the surface...

Here is how you could do what you want:

in CAS, do:
Solver(a,b,c):=BEGIN solve(a*x*x+b+x+c=0,x); END;
This will create a CAS progam (which can be called from numerical)...

Cyrille

In addition, you probably wanted to solve a*x*x+b*x+c, not a*x*x+b+x+c = x*(a*x+1)+(b+c)

Ciao.....Mike

Correct, that was a typo on my part, supposed to be a version of the quadratic formula. Because the "syntax error" is kind of vague, I was trying anything (including modifying the formula) to get it to work.

So if understand correctly, I cannot use CAS.built-in-function from within a program that uses local variables?

And will the Solver(a,b,c):=... example you listed work from within RPN/Home?

Thanks!

Bruce

Edited: 15 Oct 2013, 4:22 p.m.

From my understanding, there a two distinct types of programs, CAS and standard, which behave differently. The CAS programs need to be created form the command line but can be edited in the program editor later without loosing their capabilities.

Tim, Cyrille, Bernard, why isn't CAS the default mode for programs? If this has disadvantages it should be possible to create a CAS program within the editor or change its status (CAS/non CAS) later.

Hello

>So if understand correctly, I cannot use CAS.built-in-function from within a program that uses local variables?

Yes and no.

The Numerical system will try to make it work. and replace local variables with their values before CAS calls. This works in simple cases, however it does not work in all cases.

Cyrille

The zeros and cZeros commands work in regular programming and in the Home Modes. In Home and the regular programming editor, the "CAS." prefix must accompany zeros and cZeros. (CAS.zeros, CAS.cZeros)

cZeros allow for complex roots. The following program can be used universally:

EXPORT SOLVER(A,B,C)

BEGIN

RETURN CAS.cZeros(A*X*X+B*X+C,X);

END;

Edited: 16 Oct 2013, 11:15 a.m.