Solving a system with Newton's method in matlab?
Show older comments
I have the following system to solve with Newton's method in matlab:

I tried with two variables but I need to solve the system to get the roots a_i and a_j. for i,j=1.2....N (N=1000)
function [a,F,itr] = newtonsys(Ffun,Jfun,a0,B,L,tol ,nmax)
itr= 0; err = tol + 1; a = a0;
while err >= tol & itr< nmax
J =Jfun(a,B,L);
F =Ffun(a,B,L);
delta = - J\F;
a = a + delta;
err = norm(delta,inf);
itr = itr+ 1;
end
return
function F=Ffun(a,B,L)
F(1 ,1) =a(1)*tan(a(1))-B*(1-L*(a(1).^2+a(2).^2));
F(2 ,1) =a(2)*tan(a(2))-B*(1-L*(a(1).^2+a(2).^2));
return
function J=Jfun(a,B,L)
J(1 ,1) =tan(a(1))+a(1)*( tan(a(1)).^2+1); J(1 ,2) = 2*B*L*a(2);
J(2 ,1) =2*B*L*a(1); J(2 ,2) =tan(a(2))+a(2)*( tan(a(2)).^2+1);
return
clc
a0=[10;10]; tol=1e-5; nmax=10000; B=0.1; L=0.1;
[a,F,itr]= newtonsys(@Ffun,@Jfun,a0,B,L,tol,nmax)
I'm a newbie, somebody please help me. thanks a lot advance!
7 Comments
Torsten
on 3 Jan 2023
I think there must be a mistake in your equations. As written, every pair a_i, a_j with a_i = a_j solves your system.
I'm not sure what you mean with "i,j = 1,2,...,N".
Mery
on 4 Jan 2023
Mery
on 4 Jan 2023
Torsten
on 4 Jan 2023
Can you include a copy of this part from your textbook ?
Mery
on 4 Jan 2023
it is not an exercise, it is one of my projects and I arrived at this (solution , and the roots equation )
Then you must have made a mistake.
As already stated, all alpha_i arbitrary and equal is a solution. And I don't see how you could impose the condition that they should be different for a nonlinear solver.
Answers (0)
Categories
Find more on Correlation and Convolution 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!

