> 其他 >
matlab画图:用二分法求方程x^3cosx+6sin^5x-3=0
人气:261 ℃ 时间:2020-03-27 16:12:13
解答
用二分法,你得先找出一个根所在的区间
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
这是一个根
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版