HP Forums

Full Version: Equation stored in variable, then used by Solver
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to store an equation in a variable, then use the solve application to retrieve this equation from the variable and then solve it?
You can save the equation in a string. Likewise, I would consider a separate string for the variables.

E.g.

Code:

// formula: F=ma; we'll use the global variable F and create m and a as needed
vars:={ "m", "a" }; 
eqns:="F=m*a";

// initialize solver
local cmd,i, n:=SIZE(vars);

for i from 1 to n do
  cmd:=vars(i) + ":=0"; // set initial value to 0;
  CAS(cmd); // call CAS to evaluate cmd as if run from command line
end;

E1:=eqns; // set E1

// … code here to start the app, see STARTAPP() or STARTVIEW()

// clean up, if needed
for i from 1 to d no
  cmd:="purge(" + vars(i) +")"; // create a purge command
  CAS(cmd); // purge the variable
end;

These routines can easily to combined into a solver app to build an actual equation library with complete support for custom equations and variables. I'm currently working on one, but have been sidetracked with several other projects…
Han, is that part of program code? What did you show? How would you use it? Do you -have- to store equations to a global, capitalized variable F? Do you assign the variable list m,a and the equation prior to program start?

A working example with additional comments would be beneficial. Thanks.
I have saved formulas into CAS variables, defined solve.E1:='CAS variable' (a formula) then used Solver.

Here is a thread about this: http://www.hpmuseum.org/forum/thread-955.html

Best,
Carl
Thank you, I remember your thread. You don't use any strings, I see? Copying over a note to the cas is not really user friendly. :-(

I had the feeling Han tried to add more automation on the one hand and on the other I feel like that is an example to learn to avoid issues when programming the calculator.

What is about string usage and no string usage. I studied the patch notes and did not notice any changes concerning these topics (that is data handling) so there is a need to get used to how things are now. They are likely to last.....
I might be old or I might not have enough time for the calculator there is even the chance of being too stupit, but I did not really understand this device. I can play with it, I find interessting aspects, but once I really need it I get stuck and can't find the right way to work with it. It still did not become a tool, it is still a toy which frustrates me.
Reference URL's