HP Prime: What's wrong with this program?
#1

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

#2

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

#3

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

#4

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.

#5

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.

#6

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

#7

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.



Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending little images to the Prime (...and Program name bug?) Erwin Ried 19 7,151 12-10-2013, 05:35 PM
Last Post: Erwin Ried
  Problem with debug HP prime program, somebody help me? Carlos CM (Mexico) 6 3,241 12-05-2013, 03:07 PM
Last Post: Carlos CM (Mexico)
  HP PRIME: APP program code DISAPPEARS !! Joseph Ec 0 1,169 11-25-2013, 11:35 AM
Last Post: Joseph Ec
  Prime: Placing more than 1 item on the RPN stack in a single program? John Colvin 4 2,204 11-19-2013, 08:59 AM
Last Post: Miguel Toro
  Prime: Program size limited to 64K? Erwin Ried 4 1,981 11-17-2013, 11:42 PM
Last Post: Joseph Ec
  [HP-Prime] Picking elements from a List in a program Jean-Michel 3 1,935 11-15-2013, 04:16 AM
Last Post: dg1969
  HP Prime: Recommendation for future RPN Program Mode BruceTTT 3 2,103 11-13-2013, 10:03 PM
Last Post: BruceTTT
  HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 2,614 11-11-2013, 08:28 PM
Last Post: Davi Ribeiro de Oliveira
  [prime] Insert a breakpoint in a program for debugging ? Olivier Lecluse 3 1,725 11-09-2013, 09:41 PM
Last Post: Joseph Ec
  HP PRIME: Hide return value from program and swap Edit with Run vrrr 2 1,503 11-09-2013, 04:04 PM
Last Post: vrrr

Forum Jump: