matlab中求函数的微积分

在用matlab绘制分段函数的微积分方程时,出现报错,向量长度不一样。不知道怎么改正。原题是这样:

img

img

你好,直接

clc; clear
t = linspace(-6, 6, 10000);
f = (t<=-2|t>=2).*0 + (t<=1&t>=0).*2 + (t>-2&t<0).*(t+2) + ...
    (t<2&t>1).*(-2*t+4);
figure(1); clf
subplot(2,1,1)
plot(t, cumtrapz(t,f))
subplot(2,1,2)
plot(t(1:end-1), diff(f)./diff(t))

有帮助望采纳哟谢谢啦

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632