Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Solving Non Linear Equations =(

1 view
Skip to first unread message

Matlab Lab

unread,
Nov 24, 2009, 5:05:25 PM11/24/09
to
OK so here goes my problem. I have spent ageeeess on this! Any help would be soo appreciated! Even if you can point out where I'm wrong..!


Question:

Solve the following system of equations by using Newton's method by implementing it in Matlab:
f1 = 4 - 8*x1 + 4*x2 - 2*(x1)^3 = 0
f2 = 1 - 4*x1 + 3*x2 + (x2)^2 = 0
by using x^0 = [0.5 0.5]^T as the starting point. Report the final solution obtained and plot progress of the solution as a function of iteration counter, i.e. plot x1, x2, f1 and f2 as a function of the iteration counter. Use a small tolerance such as 0.001 for final convergence.

Note: The set of linear equations of the form Ap = b obtained at each iteration may be solved by using a command of the form p=A\b in Matlab, where A is the conatsnt matrix, b is a constant vector and p is the vector of variables for which the equations must be solved.

Here is my working:

%NON LINEAR EQUATIONS USING MATLAB
xo= [0.5 0.5]'; %where x0= [x1 x2]'
disp (xo)
k=0
Jo= [-8-6*xo(1) 4 ; -4 3+2*xo(2)^2]%jacobian matrix
disp (Jo)
fo= [4-8*xo(1)+4*xo(2)-2*xo(1)^3 ; 1-4*xo(1)+3*xo(2)-xo(2)^2]
disp(fo)
epsilon=0.001;
maxiter=200;
for k=1: maxiter
error= sqrt(fo(1)^2+fo(2)^2)
if error <=epsilon
disp 'calculation converged'
end
if k >= maxiter
end
p=Jo\fo
x=xo
x=x+p
fnew= [4-8*x(1)+4*x(2)-2*x(1)^3 ; 1-4*x(1)+3*x(2)-x(2)^2]
Jnew= [-8-6*x(1) 4 ; -4 3+2*x(2)^2]
k=k+1
disp 'number of iterations='
disp (k)
disp 'fnew ='
disp(fnew)
disp 'Jnew='
disp (Jnew)
plot (fnew,k)
return
end

Richard Hindmarsh

unread,
Nov 24, 2009, 5:35:18 PM11/24/09
to
Good try but your Jaco is wrong I think - my guess is


Jo= [-8-6*xo(1)^2 4 ; -4 3-2*xo(2)]

It's always best to check by numerical differentiation.

Matlab Lab

unread,
Nov 24, 2009, 6:47:04 PM11/24/09
to
"Richard Hindmarsh" <rc...@bas.ac.uk> wrote in message <hehn36$1g6$1...@fred.mathworks.com>...


thank you!
I tried your guess for Jacobian but still failed . matlab wont work!
any ideas why? (anyone?) maybe its something to do with the loop?

it has to converge and im not getting any convergence....... which is a nightmare

Darren Rowland

unread,
Nov 24, 2009, 9:20:17 PM11/24/09
to
I haven't tested your code, but I spot at least one error (in addition to the Jacobian as spotted by Richard).

p = Jo\(-fo);
x = x + p;

Note the minus sign on fo. Of course it can go in a number of places without changing the result. Hope that works now,
Darren

0 new messages