Azzera filtri
Azzera filtri

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 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

KSSV
KSSV il 8 Giu 2021
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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by