Non-Linear Dynamical Systems - Iteration Help? (Beginer)

조회 수: 6 (최근 30일)
Joseph Hughes
Joseph Hughes 2011년 2월 25일
Hi,
I am a total novice MATLAB user and I feel as if I am banging my head against a desk with this problem. I am aware that it is VERY simple, but as I mentioned I am very new to MATLAB, any help at all would be much appreciated.
I am studying a non-linear dynamical systems course and I'm required to write MATLAB files that will solve a non-linear system of equations of the form: f(x)=0
I am also told that the function should implement the newton iteration:
x(k+1) = x(k) - ( [df/dx(x(k))]^-1 ( f( x(k) ) )
The expression [df/dx(x(k))] is the Jacobian of f in the previous point x(k) and the initial guess x0 is provided by the user of mysolve (MySolve.m is the name we are told to call our file) I have written a program that finds the Jacobian of any matrix:
function df=MyJacobian(f,x,h)
n = length(x);
xplus = x;
xminus = x;
for i=1:n
xplus(i)=xplus(i)+h;
xminus(i)=xminus(i)-h;
df(:,i)=(f(xplus)-f(xminus))/(2.*h);
xplus(i)=x(i);
xminus(i)=x(i);
end
I know this works.
Finally we are told that the iteration should stop if both the correction (e(k+1)=x(k+1)-x(k)) and the residual (r=f(x(k))) are less than some specified tolerance 'tol' (for example 1e-10). After maxit iterations without convergence one should exit anyway, and set converged=0 (for example, maxit could be 10).
I am sorry for such a long question but once again would appreciate any help what so ever,

채택된 답변

Andrew Newell
Andrew Newell 2011년 2월 25일
I don't want to just do your homework for you, so here are a few hints that will help with the Matlab syntax. First, make a loop for k=1:maxit, so if you exceed the maximum number of iterations you just exit the loop. Inside the loop, update x and use an IF condition to test for convergence:
converged = correction < tol && residual < tol;
if converged
xsolution = current_value_of_x;
return
end
If converged is true, it is set to 1 and you finish.
  댓글 수: 1
Joseph Hughes
Joseph Hughes 2011년 3월 23일
got it working thanks for the help it is much appreciated :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by