The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP Prime: What's wrong with this program?
Message #1 Posted by BruceTTT on 15 Oct 2013, 1:05 a.m.

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

      
Re: HP Prime: What's wrong with this program?
Message #2 Posted by cyrille de Brébisson on 15 Oct 2013, 2:07 a.m.,
in response to message #1 by BruceTTT

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

            
Re: HP Prime: What's wrong with this program?
Message #3 Posted by Mike (Stgt) on 15 Oct 2013, 5:09 a.m.,
in response to message #2 by cyrille de Brébisson

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

                  
Re: HP Prime: What's wrong with this program?
Message #4 Posted by BruceTTT on 15 Oct 2013, 4:14 p.m.,
in response to message #3 by Mike (Stgt)

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.

                        
Re: HP Prime: What's wrong with this program?
Message #5 Posted by Marcus von Cube, Germany on 15 Oct 2013, 4:46 p.m.,
in response to message #4 by BruceTTT

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.

                        
Re: HP Prime: What's wrong with this program?
Message #6 Posted by cyrille de Brébisson on 16 Oct 2013, 2:00 a.m.,
in response to message #4 by BruceTTT

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

      
Re: HP Prime: What's wrong with this program?
Message #7 Posted by Eddie W. Shore on 16 Oct 2013, 11:14 a.m.,
in response to message #1 by BruceTTT

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.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall