作业帮 > 综合 > 作业

为何在MATLAB中这个代码没法实现,应如何修改?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/24 15:03:07
为何在MATLAB中这个代码没法实现,应如何修改?
clfx=0:pi/50:pi;y=cos(3*x).*exp(-x);plot(x,y,'b');str=['0.5';'1.5';'2.5 '];%求方程的三个根for i=1:3theX=fzero('cos(3*x)*exp(-x)',str(i,:)); plot(theX,0,'kd');legend('根')end
x=[0:pi/50:pi];
str=[0.5;1.5;2.5];
可通过
再问: 我想在函数图像上显示三个根
再答: 在plot后加 hold on;
再问: 能帮我优化一下代码吗???我已经通过知道提问了,每个悬赏200财富值
再答: x=[0:pi/50:pi]; y=cos(3*x).*exp(-x); str=[0.5;1.5;2.5]; %求方程的三个根 for i=1:3 theX=fzero(@(xx)cos(3*xx)*exp(-xx),str(i,1)); if i==1 plot(theX,0,'kd'); end if i==2 plot(theX,0,'r+'); end if i==3 plot(theX,0,'g*'); end legend('0.5','1.5','2.5',3); hold on; end plot(x,y,'b'); 看看是不是你想要的效果