Info

此问题已关闭。 请重新打开它进行编辑或回答。

How do I plot a trapezoidal function?

1 次查看(过去 30 天)
Harris
Harris 2013-1-16
关闭: Sabin 2022-12-19
x=linspace(-4,8,500);
y=(square((x*(3/2)+3)));
t=(sawtooth((x*(3/2)+3)));
v=[-4 8 0 2];
s=(3/2)/2;
for n=1:3
a=-(2)/(n^(2)*pi^2);
b=-(1)/(n*pi);
s=s+a*cos((n*pi*x)/2)+b*sin((n*pi*x)/2);
figure(1),subplot(2,2,n),plot(x,y,x,s,x,t),axis(v)
end
The above is what I have so far, and it looks sort of how I want it to look, except I want it to not have a line because of the use a mix of sawtooth and square waves to make it look like a proper trapezoidal wave. Also it should be periodic T+4 as opposed to 2pi periodic as sawtooth and square functions have as standard.
Any help is greatly appreciated.

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by