Roots with Bisection and Newton Raphson methods

Hi,
How can I write a single script which tries to find the roots of the following functions using both the Bisection and Newton Raphson methods? Also I want to generate a plot of the functions showing the location of the initial guess(es) and the approximated root value..
Function Interval Tolerance
f(x) = 2sin(x) + 2cos(x) [-1 1] 1x10-3
f(x) = 2-sin(x) – x2 [-1 2] 1x10-4

댓글 수: 4

madhan ravi
madhan ravi 2018년 12월 31일
편집: madhan ravi 2018년 12월 31일
upload the code that you tried
myFunction = @(x) 2.*sin(x) + 2.*cos(x);
x_lower =
x_upper =
while abs(myFunction(x_mid) >
if (myFunction(x_mid) * myFunction(x_upper)) < 0
x_lower = x_mid;
else
x_upper = x_mid;
end
x_mid = (x_lower + x_upper)/2;
end
fprintf('The root is \g\n', x_mid) %#ok<CTPCT>
% For the first function with Bisection. How do I find the lower and upper limits?
This is a very common numerical methods assignment. Have you tried searching the forum yet? Chances are this question has already been answered many times.
Jan
Jan 2019년 1월 2일
편집: Jan 2019년 1월 2일
This line is incomplete:
while abs(myFunction(x_mid) >
How do I find the lower and upper limits? - You have to guess them. There is no way to find then in advance.

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

답변 (0개)

질문:

2018년 12월 30일

편집:

Jan
2019년 1월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by