I'm ensure if this would be an efficient way to use Bisection Method to approximate x ^2 + x ^4 + 6 = x ^3 + x ^5 + 7 to produce the first 11 values of iteration

1 次查看(过去 30 天)
Using Bisection method on matlab to approximate x ^2 + x ^4 + 6 = x ^3 + x ^5 + 7 to find first 11 values of iteration. How can I show the list of 11 values of iteration when I run it?
f = @(x)(x^5-x^4+x^3-x^2+1);
a = input('Please enter lower limit, a: ');
b = input('Please enter upper limit, b: ');
n= input('Please enter no. of iterations, n: ');
tol = input('Please enter tolerance, tol: ');
fa = f(a); f(b);
i=1;
while i <= n
c = (b-a)/2.0;
p = a+c;
fp = f(p);
if abs(fp)<1.0e-20 | c<tol
fprintf('\nApproximate solutino p = %11.8f\n\n',p);
break;
else
i=i+1;
if fa*fp >0
a = p;
fa = fp;
else
b=p;
end
end
end

回答(1 个)

KSSV
KSSV 2021-6-8
Two options.
  1. MAke it a function: BisectionMethod(f,a,b,n,tol) and give inputs and call.
  2. Remove the lines input and define the variables straight away.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by