I need to write a function MySolve that will solve the nonlinear system of equations in the form
where I have f:R^n -> R^n is an arbitrary function with n-dimensions input and n-dimensional output. The function should implement the newton iteration.
I know the first line of my function looks like:
But I am having difficulty with the rest
function [x,converged]=MySolve(f,xo,tol,maxit) opts = optimset('MaxIter',maxit,'TolFun',tol); [x,~,converged] = fsolve(f,xo,opts);
(Unless, of course, this is a homework problem. In which case you might not be allowed to do that.)
This should help a little
while the_error > tol && iter <= maxit iter = iter+1; Do a whole bunch of other stuff that you have to write end
i am also having the same problem as this so far i have
%maxit maximum number of iterations to be tried.
% run a loop from 1 to maxit
%Need to call in MyJacobian
% Newton iteration
if(max(abs(x-xold)))<tol && (max(abs(x-xold)))<tol converged=1;
% Newtons iteration has converged
%Newtons iteration hasn't converged
with my jacobian function looking like this
% f: function to be differentiated %x: point where jacobian is taken % h: parameter for finite differences % outputs df: m*n matrix, jacobian of f in x.
% defines number of rows
% defines number of colums
% matrix of zeros
% runs a loop that takes two values x1 and x2 and places it % into my empty matrix df the process then produces 2 matircies of % df1 and df2
x(i)=x(i)+h; x1= f(x); x(i)=x(i)-(2*h); x2= f(x); df(:,i)=(x1-x2)/(2*h); x(i)=x(i)+h;
Play games and win prizes!Learn more