newRPL - build 1255 released! [updated to 1299]
08-09-2018, 07:34 PM (This post was last modified: 08-09-2018 07:36 PM by Claudio L..)
Post: #256
 Claudio L. Senior Member Posts: 1,840 Joined: Dec 2013
RE: newRPL - build 1089 released! [update:build 1099]
(08-09-2018 03:57 PM)rprosperi Wrote:  Claudio - Suggest you provide 2 examples, one trivial and one non-trivial, to illustrate the exact syntax of the arguments; this avoids time wasted figuring out what your explanations do/don't mean. I'm not suggesting the wording is poor, simply that for such use, interpretation can vary. For example is the list with variable names like { A B C } or {'A' 'B' 'C'}, etc.

Fair enough. Here's the trivial one: get the roots of x^2=4

Code:
 { 'X^2=4' }  @ List of equations { 'X' } @ List of variables (quoted/unquoted doesn't matter) { 1 } @ Initial guess range: left point { 10 } @ Initial guess range: right point (can be anything as long as all variables are different from the left point) 0.0001 @ TOLERANCE MSOLVE

It will return:
Code:
 { -2.000022888184 } @ List of values for each of the variables { 0.000091553258. } @ List of residuals for each expression (same as storing the result and ->NUM on the equations)

In this case it converged to the negative. If we want the positive there's 2 options:
a) Try a different initial guess range, for example { 0 } { 1 } does the trick.
b) Coerce the system with a constraint: change the list of equations to:
Code:
{ 'X^2=4' 'X>0' }
And sure enough, you'll get the positive root.

A less trivial example:

To test the Beale function from here:

Code:
 { '1.5-X+X*Y' '2.25-X+X*Y^2' '2.625-X+X*Y^3' } @ We input them as 3 separate expressions { 'X' 'Y' }    @ 2 Variables { -4.5 -4.5 }  @ Same range as in Wikipedia { 4.5 4.5 }    @ Same range as in Wikipedia 0.0001    @ Tolerance

The results are this:
Code:
 { -317914.438741247053. 1.000003117366. } @Values { 0.508944245104. 0.267885400724. -0.348176533149. } @ Residues
And from the residues we can see the algorithm didn't find a root, the value of X diverged to the negative side while Y converged to 1. Not what we expected, let's try inverting the range:

Code:
 { '1.5-X+X*Y' '2.25-X+X*Y^2' '2.625-X+X*Y^3' } @ We input them as 3 separate expressions { 'X' 'Y' }    @ 2 Variables { 4.5 4.5 }  @ Same range as in Wikipedia { -4.5 -4.5 }    @ Same range as in Wikipedia 0.0001    @ Tolerance

And now we get:
Code:
 { 2.99999918766. 0.50000000274. } { 0.000000414389. 0.000000617475. 0.000000716962. }

And now the algorithm went the other way (towards the positive side of X), converging to the proper root.

EDIT: By the way, you could also force a constraint by adding 'X>-4.5' to the list of equations.
 « Next Oldest | Next Newest »