matlab求导数Clear, dx = 0.01*2*pi ;x = 0:dx:2*pi ;y =exp(-0.5*x)*sin(2*x);F1=diff(y)/dx;F1=[f1(1),(f1(1:end-1)+f1(2:end))/2,f1(end)];Figure,plot(x, -0.5*exp(-0.5*x)*sin(2*x)+2 exp(-0.5*x)*cos(2*x),x,f1,’.’)Y=sym(‘exp(-0.5*x)*sin(2*x)’);Dy
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/29 17:14:38
matlab求导数Clear, dx = 0.01*2*pi ;x = 0:dx:2*pi ;y =exp(-0.5*x)*sin(2*x);F1=diff(y)/dx;F1=[f1(1),(f1(1:end-1)+f1(2:end))/2,f1(end)];Figure,plot(x, -0.5*exp(-0.5*x)*sin(2*x)+2 exp(-0.5*x)*cos(2*x),x,f1,’.’)Y=sym(‘exp(-0.5*x)*sin(2*x)’);Dy
matlab求导数
Clear, dx = 0.01*2*pi ;x = 0:dx:2*pi ;y =exp(-0.5*x)*sin(2*x);
F1=diff(y)/dx;
F1=[f1(1),(f1(1:end-1)+f1(2:end))/2,f1(end)];
Figure,plot(x, -0.5*exp(-0.5*x)*sin(2*x)+2 exp(-0.5*x)*cos(2*x),x,f1,’.’)
Y=sym(‘exp(-0.5*x)*sin(2*x)’);
Dy_dx=diff(y);
Df1=subs(dy_dx,’x’,x);
Hold on,plot(x,df1,’ro’),grid on
Legend(‘解析导数’,’数值差分’,’符号导数’,4)
Title(‘函数y=exp(-0.5*x)*sin(2*x)的一阶导数’,‘fontsize’,16)
这个行么
matlab求导数Clear, dx = 0.01*2*pi ;x = 0:dx:2*pi ;y =exp(-0.5*x)*sin(2*x);F1=diff(y)/dx;F1=[f1(1),(f1(1:end-1)+f1(2:end))/2,f1(end)];Figure,plot(x, -0.5*exp(-0.5*x)*sin(2*x)+2 exp(-0.5*x)*cos(2*x),x,f1,’.’)Y=sym(‘exp(-0.5*x)*sin(2*x)’);Dy
syms x
y=exp(-0.5*x)*sin(2*x)
dy=diff(y,x)
ezplot(dy) %解析微分
axis([-2*pi 2*pi -50 50])
hold on,
x1=-2*pi:0.1:2*pi;
y1=exp(-0.5*x1).*sin(2*x1);
dy1=diff(y1);
x1(1)=[];
plot(x1,dy1,'-r') %数值微分