matlab画图:用二分法求方程x^3cosx+6sin^5x-3=0
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/21 05:01:38
![matlab画图:用二分法求方程x^3cosx+6sin^5x-3=0](/uploads/image/z/2003098-58-8.jpg?t=matlab%E7%94%BB%E5%9B%BE%EF%BC%9A%E7%94%A8%E4%BA%8C%E5%88%86%E6%B3%95%E6%B1%82%E6%96%B9%E7%A8%8Bx%5E3cosx%2B6sin%5E5x-3%3D0)
matlab画图:用二分法求方程x^3cosx+6sin^5x-3=0
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
这是一个根
用二分法,你得先找出一个根所在的区间
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 interv...
全部展开
用二分法,你得先找出一个根所在的区间
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)<0
break;
end
b=b+dx;
if f(a)*f(b)<0,
break;
end
dx=2*dx;
end
end
>> 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
这是一个根
收起