Consider the nonlinear system below for unknowns x1, x2 x3 1 + x2 = 1 x1 + x2 =
ID: 2997679 • Letter: C
Question
Consider the nonlinear system below for unknowns x1, x2 x3 1 + x2 = 1 x1 + x2 = 0 Use an initial guess of (1,0). Write a MATLAB function that uses the Newton-Raphson method to solve a nonlinear system of equations. The function should accept a function handle for a the nonlinear system, a function handle for the Jacobian of the nonlinear system, a stopping tolerance, and maximum number of iterations. The function should return the solution and the error estimate for each iteration. You may use the "" command to solve the linear system. Use the following as the stopping criterion: gamma is the stopping tolerance. Write a MATLAB script that uses your Newton-Raphson function to solve the nonlinear system aboveExplanation / Answer
function [x,y,n]=newtrapf(fn,gn,xl,tol,max)
% Function to find the root of a function fn using the false-position method
%Inputs are:-
% fn gn = funtion and derivative names in quotes, respectively
% xl = guesses which bracket the root
% tol = tolerance level
% max = maximum number of iterations allowed
%Outputs are:-
% x => desired root
% y => error in calculating root
% n => number of iterations
n=0;
error=1;
errora=1000;x=1000;
while errora > tol
fl=feval(fn,xl);
gl=feval(gn,xl);
xr=xl-fl/gl;
fr=feval(fn,xr);
xold=x;
xl=xr;y=fr;
x=xr;
errora=abs((x-xold)/(x+eps)*100);
error=abs(y);
n=n+1;
if n >= max
disp('Warning! Maximun number of iterations reached but not converged yet!')
break
end
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.