{{{{{{NOTE: PLEASE READ CAREFULLY, THIS IS NOT A FUNCTION, IT IS A SCRIPT. }}}}}
ID: 3886663 • Letter: #
Question
{{{{{{NOTE: PLEASE READ CAREFULLY, THIS IS NOT A FUNCTION, IT IS A SCRIPT. }}}}}}
Write a Matlab program to implement the multidimensional version of Newton’s method. For simplicity, let x = [ x y ] and the goal is to find an (approximate) solution to the equation. This SCRIPT should use the Jacobian MATLAB command.
f (x) = 0,
where f has two components and the symbol 0 in is actually 0 = [ 0 0 ].
For example, if f (x) = [ y2 x2 3
x2 + y 3 ],
then a solution of is x = [ 1 2 ]
Near the top of your program should be your function f (HARDCODED) , your initial guess x0 (HARDCODED), the maximum number of iterations N (HARDCODED), and the tolerance epsilon(HARDCODED). You may need to research vector norms and Matlab’s associated norm command.
Explanation / Answer
%matlab script Newton_multidimensional.m
f = @(X) [X(2).^2-X(1).^2-3;X(1).^2+X(2)-3]; % The function f
df = @(X) [-2*X(1), 2*X(2);2*X(1), 1]; % Jacobian of f
x0 = [0;0]; % Initial guess
tol = 10^-6; % Tolerence
N = 100; % Maximum number of iteration
iter=0; % Initilizing the iter variable
u=feval(f,x0); % evaluating f(x0)
v=feval(df,x0);% Evaluating df(x0)
err=norm(vu); % Getting error
% loop till error less then tolerence or iteration grater than n or devision
% by zeor occurs
while (err>tol) && (iter<=n) && rank(v)==length(x0)
x1=x0-vu;% The new value
err=norm(x1-x0);% Estimating the error
x0=x1;% replacing previous iteration value with new value
u=feval(f,x0); % evaluating f(x0)
v=feval(df,x0);% Evaluating df(x0)
iter=iter+1; % Increasing the iteration index
end
if (rank(v)~=length(x0)) % Checking division by zero occurs or not
disp(' division by zero')
elseif (iter>n) % Checking convergence of method
disp(' Method failed to converge')
else % reult to the screen
fprintf('Root = %f %f ',x1);
fprintf('Number of iteration tanen = %d ',iter);
end
OUTPUT
Root =
1.000000
2.000000
Number of iteration tanen = 5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.