Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wrote a code to solve for roots using newton rampson method. I only need help in plotting approximate percentage error as a function of

I wrote a code to solve for roots using newton rampson method.

I only need help in plotting approximate percentage error as a function of number of iteration. But when you plot your But while plotting approximate percentage error , only plot from the 1st iteration and onwards. Approximate percentage error for the 0th iteration is set by you as 100%, so dont include that while plotting it as a function of iteration number.

so my question is very simple. If you could help me, I will rate of course. thanks.

This is my code. I just want you to add the plot Because I tried to do it but I am having hard time with this question.

clc;

clear; y = @(x) x - 0.8 - 0.2*sin(x); %function given y1 = @(x) 1 - 0.2*cos(x); %derivative of y x = pi/2; % initial given value tol = 1e-3; error = 0.1; %pre-specified tolerance n = 1; %first iteration while (error>tol) & (n<100) x(n+1) = x(n) - (y(x(n))/y1(x(n))); %Newton Rampson Method and where x(1) = x = pi/2 error(n) = abs(y(x(n))/y1(x(n))); n = n + 1 x(end) fprintf('n is number of iteration = %.f',n) fprintf('maxvalue = %f n\',x(end)) end x1 = 0:0.1:pi/2; y = @(x) x - 0.8 - 0.2*sin(x); plot(x1,y(x1)) grid on xlabel('x') ylabel('f(x)') title('y as a function of x')

n1=1:1:100 error(n)=abs(y(x(n))/y1(x(n))) plot(n,error(n1))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions