Post Reply 
System of non-linear equations
05-05-2014, 04:34 PM
Post: #1
System of non-linear equations
Hi,
I tried to solve a system of non linear and non polynomial equations and I managed to solve it with the Solve App and in Advanced graph mode, looking for intersections in the grap or in num mode(using Trace when I was nearby). I wanted to know if there was a way to solve non-linear systems with something like solve-fsolve-nsolve(i think I got the syntax wrong), maybe specifing for example 1..7 for x and 2..4 for y rather than putting one number, like you do in the Solve App.
Find all posts by this user
Quote this message in a reply
05-05-2014, 04:39 PM
Post: #2
RE: System of non-linear equations
Please give your example problem.

Generally, it will look like this. fsolve([x^2+y-2,x+y^2-2],[x,y]) You can give it a range by doing 0..1 for example for your intial guess.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
05-05-2014, 04:47 PM
Post: #3
RE: System of non-linear equations
I tried your system(my original problem is a bit more complex, I guess its fine to try with simple systems), how do i give the range? Because we have both x and y, should I give 2 ranges in this way : fsolve([x^2+y-2,x+y^2-2],[x,y],[0..1,0..1])?
Find all posts by this user
Quote this message in a reply
05-05-2014, 04:52 PM
Post: #4
RE: System of non-linear equations
Wait I thought I saw y^(-2) while it was y^2, I need to solve non linear non polynomial systems then lets change with: fsolve([cos(x)-x,x-y],[x,y],[0..1,0..1]) which should give us x=0.739085133215 and y=0.739085133215
Find all posts by this user
Quote this message in a reply
05-05-2014, 05:11 PM
Post: #5
RE: System of non-linear equations
Try

[x=0 .. 1 , y=0 .. 1] as the second argument to fsolve.
Find all posts by this user
Quote this message in a reply
05-05-2014, 05:54 PM
Post: #6
RE: System of non-linear equations
Thanks a lot, it works for that system, but I tried it with my problem and even with an accurate range i cant get my solution :/
my system is:
39.8344274/(y-0.1495645628)-24.52151/(y^2)=
39.8344274/(x-0.1495645628)-24.52151/(x^2)
and
39.8344274/(y-0.1495645628)-24.52151/(y^2)=
39.8344274*ln((x-0.1495645628)/(y-0.1495645628))/(x-y)-24.52151/(x*y)

the solution i am aiming for is x=1.66649546538 and y=0.238068203637, which i can get in graph mode or with the solve app giving an inital guess value like 1.5-0.2, but with fsolve even if i put ranges like 1.665-1.667 and 0.22-0,24 or initial guess 1.5-0.2
I cant get it Sad
Find all posts by this user
Quote this message in a reply
05-05-2014, 07:10 PM
Post: #7
RE: System of non-linear equations
It's slow but it works in Xcas, e.g.
Code:

fsolve([39.8344274/(y-0.1495645628)-24.52151/(y^2)=39.8344274/(x-0.1495645628)-24.52151/(x^2),39.8344274/(y-0.1495645628)-24.52151/(y^2)=39.8344274*ln((x-0.1495645628)/(y-0.1495645628))/(x-y)-24.52151/(x*y)],[x,y],[1.6,0.2])
The reason is probably because I compute symbolically the inverse of the jacobian, perhaps it would be faster if done at each Newton iteration step, once x and y have values.
For multi-dimensional systems, you can not provide intervals as guesses, this work only for 1-dimension equation where you can start a bisection.
Find all posts by this user
Quote this message in a reply
05-06-2014, 12:57 PM
Post: #8
RE: System of non-linear equations
Then why the intervals worked for fsolve([cos(x)-x,x-y],[x=0..1,y=0..1]?
Anyway I tried single values this way:
fsolve([39.8344274/(y-0.1495645628)-24.52151/(y^2)=39.8344274/(x-0.1495645628)-24.52151/(x^2),39.8344274/(y-0.1495645628)-24.52151/(y^2)=39.8344274*ln((x-0.1495645628)/(y-0.1495645628))/(x-y)-24.52151/(x*y)],[x,y],[0.8,0.25]) and I got my solution(why did you say it was slow, it was quite fast), and for some unknown reasons its important that i put an accurate y value, for example if i put 1.66 and 0.2 i doesnt work, while it works with 0.8 and 0.25
Find all posts by this user
Quote this message in a reply
05-06-2014, 01:42 PM (This post was last modified: 05-06-2014 01:49 PM by parisse.)
Post: #9
RE: System of non-linear equations
Didi you try on emulator or real calc? With inversion of jacobian after substitution (new code) it takes about 1/100s on the emulator.
The starting point is important for iterative methods: sometimes it converges, sometimes not...
For fsolve([cos(x)-x,x-y],[x=0..1,y=0..1]), the solver probably restarted from a random point, after an initial try with an invalid guess.
Find all posts by this user
Quote this message in a reply
05-06-2014, 03:06 PM (This post was last modified: 05-06-2014 03:06 PM by Gabriel.)
Post: #10
RE: System of non-linear equations
I tried with my real calc, if its 1/100 why did you say it was slow? its very fast(i can count seconds not 1/10 s or 1/100 s xD). You are right for the starting point, there must be some mathematical reason behind it.
One last thing, when I put these equations in advanced graph app for a graphic solution, it takes some time to plot the graph, like it plots a curved stripe/area and then it gets reduced till its a one dimension curve...its because they are complex non linear implicit functions ?
Find all posts by this user
Quote this message in a reply
05-06-2014, 03:37 PM
Post: #11
RE: System of non-linear equations
1/100s is on the emulator with the modified code (the original code takes about 100* more time). I don't know for the graph app.
Find all posts by this user
Quote this message in a reply
05-06-2014, 03:51 PM
Post: #12
RE: System of non-linear equations
Can i get the modified code for my real calc too? By the way thanks for the patience!!! Smile
Find all posts by this user
Quote this message in a reply
05-06-2014, 05:39 PM
Post: #13
RE: System of non-linear equations
No, but you can test it in inside Xcas (test version 1.1.1) today (windows and linux 64 bits) or tomorrow (mac and linux 32 bits).
Find all posts by this user
Quote this message in a reply
Post Reply 




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