matlab画图:用二分法求方程x^3cosx+6sin^5x-3=0
问题描述:
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
这是一个根