Question: I need help with the code for 2b. My plot would not generate any thing Here's what I got: f=@(x)cos(x)-0.3*x; %function x1=0; x2=2; while (f(x2)-f(x1))/20.001

I need help with the code for 2b. My plot would not generate any thing

I need help with the code for 2b. My plot would not

Here's what I got:

f=@(x)cos(x)-0.3*x; %function

x1=0;

x2=2;

while (f(x2)-f(x1))/20.001 %ea is relative error

ea=abs((xnew-xold)/xnew)*100;

fnew=f(xnew)

f1=f(x1)

f2=f(x2)

xnew=(x1+x2)/2

if fnew*f1

x2=xnew

else

x1=xnew

end

end

x=[1,1.5,1.25,1.125];

plot(x,ea,'k')

Find the positive solution of the equation cosx=0.3x, using the Bisection method with [0, 2] chosen as the initial interval. (a) Perform the first 4 iterations by hand and calculate the relative error for the last iteration; (b) Write a MATLAB code to find the root. The solution will be considered satisfactory if its relative error is smaller than 1%. Plot the relative error vs the number of iterations

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!