필터 지우기
필터 지우기

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