Post Reply 
Equation stored in variable, then used by Solver
05-05-2014, 10:59 PM
Post: #1
Equation stored in variable, then used by Solver
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?
Find all posts by this user
Quote this message in a reply
05-06-2014, 01:08 AM
Post: #2
RE: Equation stored in variable, then used by Solver
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…

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
05-06-2014, 07:17 AM
Post: #3
RE: Equation stored in variable, then used by Solver
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.
Find all posts by this user
Quote this message in a reply
05-06-2014, 12:03 PM (This post was last modified: 05-06-2014 12:04 PM by CR Haeger.)
Post: #4
RE: Equation stored in variable, then used by Solver
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
Find all posts by this user
Quote this message in a reply
05-06-2014, 12:15 PM (This post was last modified: 05-06-2014 12:23 PM by Angus.)
Post: #5
RE: Equation stored in variable, then used by Solver
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.
Find all posts by this user
Quote this message in a reply
Post Reply 




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