フィルターのクリア

tried bisection method opinions ?

2 ビュー (過去 30 日間)
Opariuc Andrei
Opariuc Andrei 2020 年 11 月 12 日
編集済み: John D'Errico 2020 年 11 月 12 日
So i wrote a homework using the bisection method ,code functions, some opinions on if it's correct ? if not what should be improved/changed ?
Create a script file for calculating the necesary iterations necesary for finding the solution of the equation below by the half-life /bisection method interval with an error of 1e-10. Consider [-10,10] as initial solution search interval.
x3 – x2 – sin(x)-1=0
a = -10
b = 10
er ≤ 1e-10
%% Input Data
% Ecuation x^3-x^2-sin(x)-1
% Interval [-10 , 10]
% Error 1e^-10
%% Bloc de calcul
x1=input('value for x1: ');
x2=input('value for x2: ');
y=@(x) x^3-x^2-sin(x)-1;
if y(x1)*y(x2)>0
fprintf('nu roots exist for the given interval \n');
return
end
if y(x1)==0
fprintf('x1 is one of the roots \n')
return
elseif y(x2)==0
fprintf('x2 is one of the roots \n')
return
end
for i=1:100
f=(x1+x2)/2 % bisection
if y(x1)*y(x2)< 0
x2=f;
else
x1=f;
end
if abs(y(x1))< 10^-10
break
end
end
  1 件のコメント
John D'Errico
John D'Errico 2020 年 11 月 12 日
編集済み: John D'Errico 2020 年 11 月 12 日
What is the problem? Did it find a solution? if so, then why does anything need to be changed? Do we really need to run your code, assuming that you already ran it?
To be honest, it does not look to have been written properly, since the text you ue for deciding whoch way to asplit the interval is wrong. But this is why you need to learn to use the debugger.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by