# HP Forums

Full Version: Help with solve()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Just got this calculator, coming from a Ti89

Trying to do a simple
solve(3*x^2+3*x=5,x)

All I ever get is a result of {x}

I am on the home screen, not in Cas.

What am I doing wrong?
Hello,

home upper case
cas lower case
You should try that in CAS-environment, there it provides the desired results, lower-case x, you did it in HOME with upper case X.
Arno
(03-31-2017 02:07 PM)AngryNapkin Wrote: [ -> ]Trying to do a simple
solve(3*x^2+3*x=5,x)

As for the reasoning why, A-Z in capital letters are "real number" variables. They contain by default a 0.

So in essence, evaluating what you have written is:

solve(3*0^2+3*0=5*0,0)

The basic rule is this - if you are just working with plain numbers, and want everything evaluated to an approximate numerical value, work in home. If you are working with "unknown" variables and want expression results, work in the CAS screen.
I tried using lower case variables and I get a syntax error.
Any other ideas other than using CAS?

Should this not work in home?
I am actually trying to use it within a program, and I keep getting an error. So I tried it manually in home to find out what's going on.
In home try:

solve(3*X^2+3*X-5,X)

(04-01-2017 01:02 AM)roadrunner Wrote: [ -> ]In home try:

solve(3*X^2+3*X-5,X)

So it was because I had =0 that it would not compute?
(04-01-2017 01:22 AM)AngryNapkin Wrote: [ -> ]So it was because I had =0 that it would not compute?
I find it easier to do it that way; you could also enclose the whole thing in single quotes, like this:

solve('3*X^2+3*X=5',X)

Thank you for the help. Now that this seems to be working with this syntax, I notice the result is returned as a list.

It seems the user manual is pretty poor. How do I extract the value from the list to use it in a calculation with variables?
You can set it equal to a variable such as L1, as in

L1:={<obj0>, <obj1>}

Then each element in the list can be referred to as L1(0) and L1(1) respectively.
This is truly driving me nuts.
I am simply trying to use solve() inside a program.

Here is a simple example.
EXPORT EXAMPLE()
LOCAL TMP;
LOCAL A,B,C;
A:=2000.0;
B:=1.0;
C:=0.0;
TMP:=solve((C/(π*B/12.0))-A,C);
MSGBOX("RESULT = " + TMP);
END;

If I create these variables on the home page, solve returns a result as expected. If I run this program, solve() returns an empty list {}.

What is going on? Is this a bug?
A, B, and C already exist so declaring them local confuses the compiler. Try this:

Code:
```EXPORT EXAMPLE() BEGIN  LOCAL TMP; // LOCAL A,B,C;  A:=2000.0;  B:=1.0;  C:=0.0;  TMP:=solve((C/(π*B/12.0))-A,C);  MSGBOX("RESULT = " + TMP); END;```

Quote:A, B, and C already exist so declaring them local confuses the compiler. Try this:

Well this does work using them as global variables, I am puzzled as to why?
Does A-Z exist by default and so this is why they are already declared?

Does the solve() seem to only look at global variables and not local?
Yes, A-Z and θ are built in global variables. They can only hold real numbers. There are also built in graphic, list, matrix, and complex variables.

I don't know if you can pass local variables to HOME; never tried it. You can pass local variables to CAS, but it's tricky. If you have to use local variables with the solve() command in a non CAS program I suggest you study up on the CAS() command. Start with cyrille de brébisson's document in post #9 here:

(04-03-2017 12:00 AM)roadrunner Wrote: [ -> ]A, B, and C already exist so declaring them local confuses the compiler. Try this:

Code:
```EXPORT EXAMPLE() BEGIN  LOCAL TMP; // LOCAL A,B,C;  A:=2000.0;  B:=1.0;  C:=0.0;  TMP:=solve((C/(π*B/12.0))-A,C);  MSGBOX("RESULT = " + TMP); END;```

MohrCircle()
BEGIN
//Declare Local Variables
LOCAL theta1,theta3,thetaPrime1,thetaPrime3,phiPrime,u,ch1;
LOCAL c:=1;
MSGBOX("Mohr's Circle Equations");
INPUT({{theta1,1},{theta3,1},{thetaPrime1,1},{thetaPrime3,1},{phiPrime,1},{u,1},​{c,1}},"Select given values");
CASE
IF c==0 THEN
INPUT({A,B,C,D,E,F},"Enter given values",
{"σ1=","σ3=","σ'1=","σ'3=","Ø'=","u="},
{"Major Princ Stress [kN/m²]","Min Princ Stress [kN/m²]",
"Maj Princ Eff Stress [kN/m²]","Min Princ Eff Stress [kN/m²]",
"Friction Angle [°]","Pore Water Pressure [kN/m²]"});
theta1:=A;
theta3:=B;
thetaPrime1:=C;
thetaPrime3:=D;
phiPrime:=E;
u:=F;
// Solve.SOLVE(thetaPrime1 = thetaPrime3*(TAN(45+(phiPrime/2)))^2 + 2*X*TAN(45+(phiPrime/2)),X);
c:=solve(C=D*(TAN(45+(E/2)))^2+2*X*TAN(45+(E/2)),X);
MSGBOX("c = "+c);
RETURN c;
END;
END;

Hi,

I tried the suggestion, however I also get "{X}" returned to the Home Screen. Not sure how to implement solve() in a program? Any suggestions?
You can try the following App functions:

Solve.SOLVE(equation, variable to solve for, guess)

Any variables have constants, store the values in those variables first before executing Solve.SOLVE.

Example:
X^2 + 2*T*X + 1 = T
Solve for X when T = -3, with guess X = 0

-3 > T (or T:=-3)
Solve.SOLVE(X^2 + 2*T*X 1 = T, X, 0) returns with 0.7639320225
To store the result in X:
X := Solve.SOLVE(X^2 + 2*T*X 1 = T, X, 0)

Function.ROOT( f(X) [=0], guess)

Example: Find the root nearest to 3 for X^3 - 1.2*X - 1.
Root: 1.3861532869

Caution: ROOT could find a nearby extremum (spelling?) rather than a root. Example, try the above when X= 0.
Hi thank you for replying, I realised my mistake soon after I posted. But thank you for the help!
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :