matlab syms subs eval 实例

clc;
close all;
clear;

syms T;
syms t;
syms vmax;

len = 150;

y = vmax*(1 - exp(-t/T))
y2 = vmax
y3 = vmax*exp(-t/T)

%--------------------导数----------------------
dy = diff(y,t)
dy2 = diff(y2,t)
dy3 = diff(y3,t)

%-------------------衔接点---------------------
yt0 = subs(dy,t,0) %dy不会改变
yt2 = subs(dy3,t,2*len)

%--------------------画图---------------------
t = [0:0.1:len];
T = 3;
vmax = 5;
tt = [t t+len t+2*len];
yy = eval([y zeros(1,length(t))+y2 y3]);
dydy = eval([dy zeros(1,length(t))+dy2 dy3]);

%速度图
idx = floor(length(tt)/2);
cell_string{1} = '\fontsize{12}';%<15>
cell_string{2} = '\uparrow';
cell_string{3} = '速度';
figure,
plot(tt,yy) %eval求值
text(tt(idx),yy(idx),cell_string,'Color','r','HorizontalAlignment','Center')

%加速度图
cell_string{3} = '加速度';
figure,
plot(tt,dydy)
text(tt(idx),dydy(idx),cell_string,'Color','r','HorizontalAlignment','Center')

你可能感兴趣的:(杂项)