Question
From the following code given solve the question. Now lets use the MATLAB M-file in the text. You can use that as a starting point
From the following code given solve the question.
Now lets use the MATLAB M-file in the text. You can use that as a starting point or write your own code following the pseudo-code provided. Write a MATLAB function y = func2(x) which implements the equation ( ) = -.9 2 +1.7x + 2.5 = 0. It will be used by the Newton-Raphson method M file. Use the MATLAB implementation of Newton-Raphson method to find a root of the function ( ) = -.9 2 +1.7x + 2.5 = 0 with the initial guess x0 = 5. Perform the computations until percentage approximate relative error (ea (%)) is less than ea = 2%. You are required to fill the following table.
Iteration | Xi | F(xi) | F(xi) | Eai(%) |
0 |
| -11.5 | -7.3 |
|
1 |
|
|
|
|
2 |
|
|
|
|
3 |
|
|
|
|
4 |
|
|
|
|
matlabcode
function [root,eaf,iter]=newtraph(xr,es,maxit)
% newtraph: NewtonRaphson root location zeroes
% [root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,p1,p2,...):
% uses NewtonRaphson method to find the root of func
% input:
func = @(x)-0.9*x^2 + 1.7*x + 2.5;
dfunc = @(x) -1.8*x + 1.7;
% xr = initial guess
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by function
% output:
% root = real root
% ea = approximate relative error (%)
% iter = number of iterations
if nargin<3,error('at least 3 input arguments required'),end
if nargin<4||isempty(es),es=0.0001;end
if nargin<5||isempty(maxit),maxit=50;end
eaf(1)=0;
iter = 0;
while (1)
xrold = xr;
xr = xr - func(xr)/dfunc(xr);
iter = iter + 1;
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end
if ea <= es || iter >= maxit, break, end
eaf(iter)=ea;
fx=-0.9*5^2 + 1.7*5 + 2.5
df= -1.8*5 + 1.7
end
root = xr;
disp("")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started