Post Reply 
Equation stored in variable, then used by Solver
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
Post Reply 


Messages In This Thread
RE: Equation stored in variable, then used by Solver - Han - 05-06-2014 01:08 AM



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