- MAke it a function: BisectionMethod(f,a,b,n,tol) and give inputs and call.
- Remove the lines input and define the variables straight away.
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 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
KSSV
on 8 Jun 2021
Two options.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!