System of non-linear equations - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: System of non-linear equations (/thread-1247.html) System of non-linear equations - Gabriel - 05-05-2014 04:34 PM 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. RE: System of non-linear equations - Tim Wessman - 05-05-2014 04:39 PM 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. RE: System of non-linear equations - Gabriel - 05-05-2014 04:47 PM 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])? RE: System of non-linear equations - Gabriel - 05-05-2014 04:52 PM 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 RE: System of non-linear equations - Helge Gabert - 05-05-2014 05:11 PM Try [x=0 .. 1 , y=0 .. 1] as the second argument to fsolve. RE: System of non-linear equations - Gabriel - 05-05-2014 05:54 PM 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 RE: System of non-linear equations - parisse - 05-05-2014 07:10 PM 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. RE: System of non-linear equations - Gabriel - 05-06-2014 12:57 PM 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 RE: System of non-linear equations - parisse - 05-06-2014 01:42 PM 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. RE: System of non-linear equations - Gabriel - 05-06-2014 03:06 PM 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 ? RE: System of non-linear equations - parisse - 05-06-2014 03:37 PM 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. RE: System of non-linear equations - Gabriel - 05-06-2014 03:51 PM Can i get the modified code for my real calc too? By the way thanks for the patience!!! RE: System of non-linear equations - parisse - 05-06-2014 05:39 PM 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).