Question: This is Matlab function [root,iter,ea] = newtraph(func,dfunc,xr,es,maxit) % Inputs: % % % % Outputs: % if nargin maxit=50; % sets the max interactions =50 end
This is Matlab
function [root,iter,ea] = newtraph(func,dfunc,xr,es,maxit)
% Inputs:
%
%
%
% Outputs:
%
if nargin
maxit=50; % sets the max interactions =50
end
if nargin
es=0.01; % step size .01
end
iter = 0; % iteration set to 0
while (1) % while loop for 1
xrold = xr; % sets the old gas to xr so we can change it later on and run through multiple iterations
xr = xr - func(xr)/dfunc(xr); % this is the formula for the newtraph
iter = iter + 1; % takes our iteration and adds one to the original to use as the next gues point
if xr~=0 % if then
ea = 100*abs((xr-xrold)/xr); % fiding the error
xrv(iter) = xr; %root vector storing to grab values later
eav(iter) = ea; %error vector storing to grab values later
inerv(iter) = iter; %iteration vector storing to grab values later
end
if ea = maxit % if error is greater or equal if true then set interations lessthen or equal to maxit. if not then stop
break % stopes statements from being executed after this point
end
end
root = double(xr);
subplot(2,1,1) % subplot makes it able to print multiple graphs on 1 window has 2 rows 1 column and 1 Position
plot(inerv,xrv)% plots with x,y axis
xlabel('iteration'); %label x
ylabel('root estimate'); %label y
subplot(2,1,2)% subplot makes it able to print multiple graphs on 1 window has 2 rows 1 column and 2 Position
plot(inerv,eav)% plots with x,y axis
xlabel('iteration'); %label x
ylabel('Error'); %labely
end
![This is Matlab function [root,iter,ea] = newtraph(func,dfunc,xr,es,maxit) % Inputs: % % %](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f390d7f151a_35966f390d7718e9.jpg)
Lab 5 Homework 30 points Use the Newton-Raphson Method Code provided in lab. 1. To find the inverse of a number a, the following equation may be used: f(c) = a 0 F C where c is the inverse of a . Use the Newton-Raphson method of finding roots of equations, to find the inverse of a = 2.5 Lab 5 Homework 30 points Use the Newton-Raphson Method Code provided in lab. 1. To find the inverse of a number a, the following equation may be used: f(c) = a 0 F C where c is the inverse of a . Use the Newton-Raphson method of finding roots of equations, to find the inverse of a = 2.5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
