matlab二分法程式設計 用二分法求方程的根:x*x+53.99x-0.054=0

matlab二分法程式設計 用二分法求方程的根:x*x+53.99x-0.054=0


這是原始程式碼:在matlab中保存為:bisection.mfunction ;rtn=bisection(fx,xa,xb,n,delta)% ;二分法解方程% ;fx是由方程轉化的關於x的函數,有fx=0.% ;xa ;解區間上限% ;xb ;解區間下限%解區…



matlab畫圖:用二分法求方程x^3cosx+6sin^5x-3=0


用二分法,你得先找出一個根所在的區間
function [a,b]=findbracket(f,x0)
%f is the function evaluated
%x0 is the starting point
%a is the left boundary
%b is the right boundary
%[a,b] is the interval around x0 wanted
a=x0;
b=x0;
dx=0.001;
while f(a)*f(b)>0
a=a-dx;
if f(a)*f(b)f=@(x)(x^3)*cos(x)+6*(sin(x))^5-3
f =
@(x)(x^3)*cos(x)+6*(sin(x))^5-3
>> [a,b]=findbracket(f,1)
a =
0.9850
b =
1.0070
所以在這個區間內有一個根,然後再用二分法精確到0.00001
>> p=bisection(f,a,b,1e-5)
p =
0.9919
這是一個根



利用二分法求方程x2-2=0的一個正根的近似值
精確到0.1


根據函數零點理論:對於區間[a,b],若f(a)•;f(b)0,∴f(x)在(1,3/2)上有零點;
②取(1+3/2)/2=5/4,f(5/4)=25/16 - 2=25/16 - 32/16 =-7/16