Help with solve() - 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: Help with solve() (/thread-8074.html) Help with solve() - AngryNapkin - 03-31-2017 02:07 PM 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? RE: Help with solve() - mop80087 - 03-31-2017 03:19 PM Hello, home upper case cas lower case RE: Help with solve() - Arno K - 03-31-2017 03:22 PM 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 RE: Help with solve() - Tim Wessman - 03-31-2017 04:03 PM (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. RE: Help with solve() - AngryNapkin - 03-31-2017 04:18 PM 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? RE: Help with solve() - AngryNapkin - 03-31-2017 04:26 PM 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. RE: Help with solve() - roadrunner - 04-01-2017 01:02 AM In home try: solve(3*X^2+3*X-5,X) -road RE: Help with solve() - AngryNapkin - 04-01-2017 01:22 AM (04-01-2017 01:02 AM)roadrunner Wrote:  In home try: solve(3*X^2+3*X-5,X) -road So it was because I had =0 that it would not compute? RE: Help with solve() - roadrunner - 04-01-2017 01:44 AM (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) -Road RE: Help with solve() - AngryNapkin - 04-01-2017 02:31 AM 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? RE: Help with solve() - Brad Barton - 04-01-2017 03:48 AM You can set it equal to a variable such as L1, as in L1:={, } Then each element in the list can be referred to as L1(0) and L1(1) respectively. RE: Help with solve() - AngryNapkin - 04-02-2017 09:38 PM 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? RE: Help with solve() - roadrunner - 04-03-2017 12:00 AM 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;``` -road RE: Help with solve() - AngryNapkin - 04-03-2017 01:00 AM 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? RE: Help with solve() - roadrunner - 04-03-2017 01:25 AM 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: http://www.hpmuseum.org/forum/thread-6218.html -road RE: Help with solve() - Kiyan - 11-09-2017 06:00 PM (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;``` -road 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? RE: Help with solve() - Eddie W. Shore - 11-09-2017 09:07 PM 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. RE: Help with solve() - Kiyan - 11-09-2017 09:48 PM Hi thank you for replying, I realised my mistake soon after I posted. But thank you for the help!