フィルターのクリア

bisection method.

1 回表示 (過去 30 日間)
ruth okoh
ruth okoh 2011 年 12 月 10 日
回答済み: Vidhi Agarwal 2023 年 6 月 2 日
x^3 - 1.6x^2 - 2.4x + 0.3 finding the midpoint through bisection method, using both matcad & mathlab.
  2 件のコメント
Walter Roberson
Walter Roberson 2011 年 12 月 10 日
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Jan
Jan 2011 年 12 月 10 日
Dear ruth okoh, do you have a question?

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

回答 (1 件)

Vidhi Agarwal
Vidhi Agarwal 2023 年 6 月 2 日
Please find the attched Code for the following question
% Define the function f(x)
f = @(x) x^3 - 1.6*x^2 - 2.4*x + 0.3;
% Define the interval [a,b]
a = -1;
b = 3;
% Define the tolerance (the maximum error allowed)
tol = 1e-6;
% Set the maximum number of iterations
max_iter = 1000;
% Initialize the variables
iter = 0;
midpoint = (a + b) / 2;
fa = f(a);
fb = f(b);
% Use a while loop to iteratively refine the midpoint
while abs(f(midpoint)) > tol && iter < max_iter
midpoint = (a + b) / 2;
fm = f(midpoint);
if fm == 0
break;
elseif sign(fm) == sign(fa)
a = midpoint;
fa = fm;
else
b = midpoint;
fb = fm;
end
iter = iter + 1;
end
% Display the results
fprintf('The midpoint of the function f(x) = x^3 - 1.6x^2 - 2.4x + 0.3 is: %f\n', midpoint);
The midpoint of the function f(x) = x^3 - 1.6x^2 - 2.4x + 0.3 is: 0.116597
This code provide the solution of equation f by bisection method.
if you want to find olution of more equation by bisection method you can just change the function f.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by