Post Reply 
Programming solve function
06-04-2018, 05:07 PM (This post was last modified: 09-17-2019 05:28 PM by Gene222.)
Post: #1
Programming solve function
I am having trouble programming the SOLVE and fsolve functions, and I am not sure of what I am doing wrong. I can run solve on the HP Prime, but I can't programmatically solve the equation.
[Image: solve1.png] [9/17/19. Replaced tinypic image]

EDIT 6/4/18 corrected error in code with the radius, but still can't get code to work.
Code:
EXPORT OldAAngleSetting,theta,radius,x,q,v;

EXPORT SolveProgramExamples()
BEGIN
OldAAngleSetting:=AAngle; //save apps angle mode setting
AAngle:=1; //Switch to apps radian angle mode

// SOLVE Example ----------------------------------------
//initialize variables
X:=0;
theta:=0;
//input
V:=2;
R:=0.75;
Q:=3.1;
Solve.SOLVE(X-SIN(X)=2*Q/(V*R^2),X,3);
theta:=X;
PRINT();
PRINT("SOLVE example");
PRINT("X="+X);
PRINT("theta="+theta);

// fsolve Example ------------------------------
//initialize variables
x:=0;
theta:=0;
//input
v:=2;
radius:=0.75;
q:=3.1;
theta:=CAS("fsolve(x-SIN(x)=2*q/(v*radius^2),x=3)");
PRINT(" ");
PRINT("fsolve example");
PRINT("x="+x);
PRINT("theta="+theta);

AAngle:=OldAAngleSetting; //restore previous apps angle mode setting
END;
Find all posts by this user
Quote this message in a reply
06-05-2018, 12:33 AM
Post: #2
RE: Programming solve function
The value returned by SOLVE was not stored.
The CAS has a 'radius' command, so it will not be able to directly capture the exported variable of the program.

Code:
EXPORT OldAAngleSetting,theta,rads,q,v; //← x isn't necessary, radius → rads

EXPORT SolveProgramExamples()
BEGIN
OldAAngleSetting:=AAngle; //save apps angle mode setting
AAngle:=1; //Switch to apps radian angle mode

// SOLVE Example ----------------------------------------
//initialize variables
theta:=0;
//input
V:=2;
R:=0.75;
Q:=3.1;
X:=Solve.SOLVE(X-SIN(X)=2*Q/(V*R^2),X,3); //←
theta:=X;
PRINT();
PRINT("SOLVE example");
PRINT("X="+X);
PRINT("theta="+theta);

// fsolve Example ------------------------------
//initialize variables
theta:=0;
//input
v:=2;
rads:=0.75;
q:=3.1;
theta:=fsolve("x-SIN(x)=2*q/(v*rads^2),x=3"); //←
PRINT(" ");
PRINT("fsolve example");
PRINT("x="+theta); // ←
PRINT("theta="+theta);

AAngle:=OldAAngleSetting; //restore previous apps angle mode setting
END;

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
06-05-2018, 03:07 AM (This post was last modified: 06-05-2018 03:08 AM by Carlos295pz.)
Post: #3
RE: Programming solve function
If you persist in using "radius", you can evade the name resolution CAS-Home by manufacturing the data in strings before sending it to the CAS, in this way it can be done for similar cases.

Code:
theta:=fsolve(EVAL("x-SIN(x)=2*q/(v*"+radius+"^2),x=3"));

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
06-05-2018, 03:07 AM
Post: #4
RE: Programming solve function
Thanks. Your "fsolve" equation changes also work with the "solve" command, which is what I initially wanted to do. I used "radius" to differentiate the pipe radius from the hydraulic radius "r". Geez...
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)