Over determined system of non-linear equations using lsqnonin function
Show older comments
Hi.
4 equations are:
101/x + 0.00526*y = 1 ;
88.8/x+0.00556*y = 1;
82/x+0.00714*y =1 ;
0.5*x = 1.304*y
I am having trouble using lsqnonlin function to solve these equations. Please help. Thanks in advance.
1 Comment
Star Strider
on 27 May 2016
It would help if you post (and format) your code. (Highlight / select your code, then use the [ {} Code ] button to format it.)
Answers (1)
John D'Errico
on 27 May 2016
Why do people not like to plot things? 3 of your equations are hyperbolic arcs. The other is a straight line.
h(1) = ezplot('101./x + 0.00526*y - 1',[-1000,1000])
hold on
h(2) = ezplot('88.8./x+0.00556*y - 1',[-1000 1000])
h(3) = ezplot('82/x+0.00714*y - 1',[-1000 1000])
h(4) = ezplot('0.5*x - 1.304*y',[-1000 1000])
set(h(1),'color','r')
set(h(2),'color','g')
set(h(3),'color','b')
set(h(4),'color','y')
grid on

If I zoom into the interesting region,

Don't just throw something at a solver and expect an intelligent result to come out. Look at it, see if anything meaningful comes to mind.
Personally, I'd suggest there is no "solution" to that system that is great. :) But [x,y]=[130,50] seems a guess as at least a reasonable compromise. That also yields reasonable starting values. However, I'll start it out someplace not that close, to see how good is my eye.
xy0 = [100 40];
fun = @(xy) [101/xy(1) + 0.00526*xy(2) - 1;...
88.8/xy(1)+0.00556*xy(2) - 1; ...
82/xy(1)+0.00714*xy(2) - 1 ;
0.5*xy(1) - 1.304*xy(2)];
xy0 = [100 40];
xy = lsqnonlin(fun,xy0)
Local minimum found.
Optimization completed because the size of the gradient is less than
the default value of the optimality tolerance.
<stopping criteria details>
xy =
130.08 49.876
Honestly, I picked [130,50] by eye, before I ever ran the code. I should ask for a raise. Maybe double my salary. Sadly
2*0
ans =
0
Even MATLAB knows what I'm worth. :)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!