I also suggest that you look at references to the use of NR for power
system load flow problems which are non-linear and generally expressed
in terms of complex numbers in the polar format. These do converge
well. I haven't written one in J but one written in APL has 11 readable
lines-most of which are setting up the matrices to solve (with no
complex number capability- J should be more compact).
Don
On 2017-08-10 1:10 PM, Ian Clark wrote:
Is it also possible to solve a system of equation like the following
one… ?
Basically, yes.
Because not only can x = (x1,x2) be a vector, but so can y = (y1,y2) in
this adaptation of your equations:
y1 = a*(1-x1)
y2 = b*(x2-x1^2)
TABULA is an app (distributed as a JAL "addon") which employs
Newton-Raphson (occasionally) to "solve" systems of non-linear equations
supplied by the user. "Solve" includes replacing y2, say, with (y2+∆y2) and
relying on TABULA to adjust x2, x1 and y1 accordingly.
…And to do so without forcing a debate with the clueless user as to what
"accordingly" means here.
As you'll be aware, N-R algorithms don't always converge, especially when
you don't have control over what the user throws at you. Pure
mathematicians do; engineers don't. Hyperbolic functions behave badly, e.g.
y-->(y+∆y) in: y = k/x unless (∆y) is "small enough"… again there is no
point asking the poor user what "small enough" is supposed to mean in this
instance.
For a problem that has no general solution, TABULA performs remarkably well
with the systems of (sometimes non-linear) equations that physicists and
engineers typically need solving. Occasionally TABULA throws up its hands
in despair – as even the perfect app would have to, when faced with y-->(y+∆y)
in: y = sin(x) whenever ∆y takes (y+∆y) outside the domain: [-1,1].
I suggest you read these articles:
http://code.jsoftware.com/wiki/TABULA/LaunchElephant
http://code.jsoftware.com/wiki/TABULA/ChurchClock-NEW
as examples of the sort of empirical problem TABULA is designed to address.
Then examine the code of the addon: CAL, the engine used by TABULA to do
the real work. Particularly the verb: (inversion) and its ancillary (and
alternative) verbs.
… in a similar elegant manner?
Since TABULA is an empirical tool for non-mathematicians, such as K-12
pupils and college students training to be physicists, engineers and
ecologists, it sacrifices a great deal of elegance in the interests of
generality and practicality, not to mention giving the user a
comprehensible answer when things go wrong. Thus in practice the "_" in "
N^:_" needs replacing by a finite value simply to timeout the infinite
iterations which can and do occur.
Accordingly you'll see that the different variants of the verb (inversion)
are nowhere near as pretty as: N=: 1 : '- u % u d. 1'
You don't say whether you are a mathematician (in particular a functional
analyst) or an engineer. Whichever it is, you'll either be baffled by, or
scornful of, the code in CAL.ijs. But it should give you a bit of a start
in whatever you want to do.
On Thu, Aug 10, 2017 at 7:07 PM, Martin <[email protected]> wrote:
Hi there,
J looks very interesting. I have no previous experience with array
languages and, being curious, started to experiment. Now, I would
like to solve a system of non-linear equations. I could only examples
solving single equations like this one:
N=: 1 : '- u % u d. 1' NB. Adverb implementing Newton-Raphson
iteration.
(_2 + *:) N^:_ ]1 NB. Find root of “0 = _2+x^2”, starting guess
of “1”.
Is it also possible to solve a system of equation like the following
one in a similar elegant manner?
f1(x) = a*(1-x1)
f2(x) = b*(x2-x1^2)
Example from https://www.gnu.org/software/gsl/doc/html/multiroots.html#
examples
Thanks for any ideas!
-Martin
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm