>>symsx;f=inline('sin(x)-x*(1/3)')
f=
Inlinefunction:
f(x)=sin(x)-x*(1/3)
>>fplot(f,[-10,10])
>>grid
由图像可以看出在[-4,-2]和[2,4]之间有两个非零解,所以使用下面两条命令
>>[xroot,y]=fsolve(f,[2,4],1e-5)
Optimizationterminated:first-orderoptimalityislessthanoptions.TolFun.
xroot=
2.2788626600758282.278862660076503
y=
1.0e-012*
0-0.663136212608606
>>[xroot,y]=fsolve(f,[-4,-2],1e-5)
Optimizationterminated:first-orderoptimalityislessthanoptions.TolFun.
xroot=
-2.278862660076468-2.278862660075828
y=
1.0e-012*
0.6296074772649260
注意这里最终结果xroot是最终的区间(精度为1e-5),也就是说方程的根在[2.2788626600758282.278862660076503]之间,y是把该值代入f得到的函数值.