HP Prime Program using Solve function

02012020, 06:43 PM
Post: #1




HP Prime Program using Solve function
I am trying to write a program on my HP Prime to solve for Z but when I use the solve function it is only returning 0. When I do the same equation on the CAS it works but not in my actual program. This is my code:
Code:
I cant seem to figure out how to get the solver function to work inside my program. If anyone knows how to fix this problem I would greatly appreciate the help. 

02022020, 10:11 AM
Post: #2




RE: HP Prime Program using Solve function
I see a few problems pertaining to the lines
Code: solve(0:=1+βq*β*((Zβ)/(Z+β*Є)/(Z+s*β)),Z,1); I assume "0:=" was a typo for "0=" (otherwise you are trying to assign a value to zero). By using capital Z here you are inserting the value of the permanent global numeric variable Z, not the symbol Z. So if Z happened to be 5, then you are essentially typing: Code: solve(0:=1+βq*β*((5β)/(5+β*Є)/(5+s*β)),Z,1); The solve command does not assign a value to the variable it is solving for. For example, in CAS, if you enter solve((x^23) = 0,x) it returns {{sqrt(3),sqrt(3)} but does not assign this list to x. In your case, you might be tempted to use Code: Z:=solve(0:=1+βq*β*((5β)/(5+β*Є)/(5+s*β)),5,1); I assume there were no other lines intended before the final END. Finally, I'm not familiar with fugacity, but ((Zβ)/(Z+β*Є)/(Z+s*β)) has redundant ()'s and is the same as (Zβ)/((Z+β*Є)*(Z+s*β)). I thought I should ask if this really what you intended? Hope this helps at least a little. 

02032020, 01:46 AM
Post: #3




RE: HP Prime Program using Solve function
Thank you for the reply. The "0:=" was a typo but I am not trying to assign a list to the Z variable. I am trying to solve for a numerical value of Z. I want the solve function to assign that value to Z. I am able to do is in the solve app if I insert the equation there then solve for Z but I want to be able to do that without having to leave the program. When I have run the program it will return a value of 0. the whole code is as follows:
Code:
Code: //Z for vapor 

02032020, 05:09 PM
(This post was last modified: 02032020 06:21 PM by Albert Chan.)
Post: #4




RE: HP Prime Program using Solve function
We had similar issues with limits, which got resolve with assume(¬x,symbol)
https://www.hpmuseum.org/forum/thread11...#pid106011 (02032020 01:46 AM)Grayhek Wrote: Looks like Z is just a quadratics. You can provide Z quadratic coefficients, and use proot, solving both roots. 

02032020, 07:37 PM
Post: #5




RE: HP Prime Program using Solve function
This is a cubic equation on states. unfortunately it is not a quadratic equation but it is a cubic equation.


02042020, 12:29 AM
Post: #6




RE: HP Prime Program using Solve function
Three comments:
1. From a program, solve() has to be sent to CAS via a string; 2. The variable you are solving for should not exist. In the edited program below I used lower case z. You have to use a variable that doesn't exist anywhere on your calculator; 3. Solve doesn't assign the answer to the variable, it just returns an answer; you have to assign that to a variable in your program. With this in mind, here is a modified program: Code:
Hope this helps. road 

02052020, 04:52 AM
Post: #7




RE: HP Prime Program using Solve function
(02042020 12:29 AM)roadrunner Wrote: Three comments: Can you tell us why in a program using fsolve, the variable you are solving for should not exist anywhere on the calculator? 

02052020, 06:14 AM
Post: #8




RE: HP Prime Program using Solve function
Hello,
Well, it is not a must, but it avoids unwanted evaluation which might happen sometimes, depending on the function. Also, any program involving the cas would work better as a CAS native program rather than as a PPL to cas function call... All UI works better in PPL, but if you have all your variables as CAS variable, you will save a lot of time in CAS to PPL transforms of all of this. you can use the #cas #end syntax in your program to include a cas block... Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. 

02062020, 04:59 AM
Post: #9




RE: HP Prime Program using Solve function
(02052020 06:14 AM)cyrille de brébisson Wrote: Also, any program involving the cas would work better as a CAS native program rather than as a PPL to cas function call... I am not a supporter of #cas #end, since if someone uses "restart" every program created there would be deleted and the source container should be recompiled. That for a common user may not be intuitive. "restart" is often used a lot to quickly solve the residual configurations and variables that many programs leave indiscriminately. The alternative is that we can use local CAS variables, that is very good, but that there are no local CAS functions is problematic, maybe that is impossible perhaps, so I have always opted for the HomeCAS interaction, in 2017 it seemed to be standardized but it has been broken a few times and recently I have found that HomeCAS works differently in G2. Viga C  TD  FB 

02202020, 01:53 AM
Post: #10




RE: HP Prime Program using Solve function
The solution to this problem was actually simple. Once I typed "solve" in capital letters ("SOLVE") the CAS function worked properly.


02202020, 06:03 AM
Post: #11




RE: HP Prime Program using Solve function
Hello,
The uppercase SOLVE function is normally the function app SOLVE function and uses the HP numerical solver. the lowercase, cas, solve function uses the CAS which will first try sybolic solving before moving on to numerical methods. Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. 

« Next Oldest  Next Newest »

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