A=2;%定义A为一个数值
t=-2:0.1:2;%t定义为-2~2
if t<0
r=0;
else
r=1/2*A*t^2;
end
plot(t,r)
title('function r(t)')%标题
xlabel('t')
ylabel('r')
lengend(‘t’,’r‘)
grid on
盲打,未开matlab.大概就是这么实现的,先试试呃,果然错了,改成这样就好了:A=2;%定义A为一个数值i=1;for t=-2:0.1:2if t<0r(i)=0;elser(i)=1/2*A*t.^2;endi=i+1;endt=-2:0.1:2;plot(t,r)title('function r(t)')%标题xlabel('t')ylabel('r')legend('r')grid on突然想到还有一种更简单的方法:A=2;t1=-2:0.1:0;t2=0:0.1:2;t=[t1,t2];r1=0*t1;r2=1/2*A*t2.^2;r=[r1,r2];plot(t,r)title('function r(t)')%标题xlabel('t')ylabel('r')legend('r')grid on%这个我试过可以的了所以果然不跑一下程序是不行的啊。。