Question

Using MATLAB and bisection Find the first 10 roots of the function y(x) = cos(5x). Note...

Using MATLAB and bisection

Find the first 10 roots of the function y(x) = cos(5x).

Note you will need to have a script file that steps along the x-axis and calls bisect when a root bracket is found.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

clc%clears screen
clear all%clears history
close all%closes all files
format long
f=@(x) cos(5*x);
findroots(0:0.1:6,f,1e-5)
function R=findroots(x,f,tol)

R=[];
a=x(1);
count=1;
for kk=1:length(x)
if(f(a)*f(x(kk))<0)
b=x(kk);
iter = 0;
  
if f(a)*f(b)>=0

disp('No Root')

else

prev = (a+b)/2;
p=a;
while (abs(f(p))>tol)
prev=p;

iter =iter+ 1;

p = (a+b)/2;

if f(p) == 0
  
break;

end

if f(a)*f(p)<0

b = p;

else

a = p;

end
if(iter==100)
disp('the required accuracy is not reached in 50 iterations');
end
end

end
R(count)=p;
count=count+1;
a=x(kk);
else
a=x(kk);
end

end
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Using MATLAB and bisection Find the first 10 roots of the function y(x) = cos(5x). Note...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT