Problem on bisection method in MATLAB

Write a program in MATLAB which will give as output all the real solutions of the equation sin(x)=x/10. The solutions should be accurate up to the second decimal place and should be obtained using the bisection method. Note that the program should be written efficiently i.e, a loop should be introduced so that the bisection method is applied repeatedly to obtain all the solutions (starting values should not be entered manually for each root). The program should display all the solutions as output.

답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 10월 20일

0 개 추천

댓글 수: 4

raj k
raj k 2020년 10월 21일
Hi.
Thank you for the reply. I understand the basic code and the logic behind the bisection method. The step I am struck at is the step in which the question demands that we write a loop to generate starting values(a and b) and use them to determine all the solutions. As of now, all the code I have come across assume that the starting values 'a' and 'b' are user input. Hence I am looking at a way to generate a loop which will input all the possible valid values of 'a' and 'b' and input that into the bisection program to find all the solutions of the equation.
Any idea on how I can proceed on this?
Ameer Hamza
Ameer Hamza 2020년 10월 21일
There are infinitely many choices of end-points. How to choose which one to use in for-loop.
John D'Errico
John D'Errico 2020년 10월 21일
If you understand it, then you need to make an effort. surely you can find pseudo-code for a bisection method? If so, then look how the loop is structured. Now think about how loops work in MATLAB. The mode effort you make, the more likely you will get help. Show the code you are writing. look at it. Think about how it must work. Look at the code you wrote, and ask why it did not work.
raj k
raj k 2020년 10월 22일
Hi. So this is the code I am using
a1=pi;
b=3*pi/2;
Tol=1e-8;
error=abs(a1-b);
fa=FofX2(a1);
fb=FofX2(b);
iterations=0;
while(error>Tol)
format long;
c=(a1+b)/2
fc=FofX2(c);
iterations=iterations+1
if(fa*fc<=0)
b=c;
fb=fc;
else
a1=c;
fa=fc;
end
error=abs(b-a1);
end
disp(c)
disp(iterations)
Can you look at it and give me some leads? I am trying to figure out how to do it.

댓글을 달려면 로그인하십시오.

Andy
Andy 2020년 10월 22일

0 개 추천

Valid starting points for a and b are the turning points of the function sin(x)-(x/10)=0. Determine the turning points then use tp(1) and tp(2) as the first a and b, then tp(2) tp(3)

댓글 수: 3

raj k
raj k 2020년 10월 22일
Hi. Yes, The method you said is the conventional method. But what I am looking is the way when the user does not input the starting values, but a loop determines these starting values. Also can you clarify what is tp(1) and tp(2). Can you suggest a loop where the program finds all the starting values a and b for each of the root by itself?
Andy
Andy 2020년 10월 22일
tp(1) is the first turning point, tp(2) is the second and so on.
You can write code to determine the turning points by differentiating the function and finding the peaks. There is a findpeaks function on file exchange.
shubh aggarwal
shubh aggarwal 2020년 10월 28일
@ raj k can you share the final code if your problem was solved

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Code Execution에 대해 자세히 알아보기

질문:

2020년 10월 20일

댓글:

2020년 10월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by