manual:chapter3:solver

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:chapter3:solver [2021/09/24 09:37]
claudio
manual:chapter3:solver [2021/09/24 09:56] (current)
claudio
Line 22: Line 22:
 This command requires all its input arguments as lists, even if there's a single item, except the tolerance which is a real number. This command requires all its input arguments as lists, even if there's a single item, except the tolerance which is a real number.
  
 +==== Example: Solving a single equation ====
  
 +Let's assume the user needs to find a root of ''%%'2*X+4=8'%%''. The first step is to provide the list of equations, in this case just one: ''{ '2*X+4=8' }''. Then we need to provide a list of the variables to solve for, in this case only one ''{ 'X' }''. Now it's time to decide where the algorithm will begin exploring. Let's say our guess is that the root is between 0 and 10. First, we need to provide a list of the lower bounds for all variables, in this case it's just one ''{ 0 }'', and then a list of the upper bounds ''{ 10 }''. Finally, we need to provide a tolerance. Let's say 4 decimal figures are good, so we'll use ''1E-4''.
 +
 +We are now ready to run the ''MSOLVE'' command. The stack looks now like this:
 +
 +<code>
 +5:                { '2*X+4=8' }
 +4:                      { 'X' }
 +3:                        { 0 }
 +2:                       { 10 }
 +1:                         1E-4
 +
 +……………………………………………………………………………………
 +MSOLVE
 +</code>
 +
 +Which will produce:
 +
 +<code>
 +2:           { 1.999969482422 }
 +1:          { -0.000061035156 }
 +</code>
 +
 +The first list returned in level 2 contains the value found for all variables, in this case ''X=2'' was the exact solution. The list in level 1 has the residuals of all equations. The residual is defined as the difference between the left and right sides of the equation. Notice that the residual is within the requested tolerance. Requesting a tighter tolerance would produce a result for ''X'' closer to ''2'' but at the expense of longer running time to find the solution.
  
  
  • manual/chapter3/solver.1632501453.txt.gz
  • Last modified: 2021/09/24 09:37
  • by claudio