Solving a system with Newton's method in matlab?

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

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".
1)"i,j = 1,2,...,N". means that a_i and a_j are vectors
2)I know that a_i = a_j solves the system but I need a_j and a_i to calculate this sum for
What is the nonlinear equation that the alpha_i are solutions of ? This cannot be the two you posted since they don't fix the alpha_i.
are the roots of this equation
I tried to use Newton's method to get them, but without result.
Can you include a copy of this part from your textbook ?
it is not an exercise, it is one of my projects and I arrived at this (solution , and the roots equation )
the solution:
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.

Sign in to comment.

Answers (0)

Products

Release

R2013a

Asked:

on 3 Jan 2023

Edited:

on 4 Jan 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!