How do I plot a trapezoidal function?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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.
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!