Info

This question is closed. Reopen it to edit or answer.

How do I plot a trapezoidal function?

4 views (last 30 days)
Harris
Harris on 16 Jan 2013
Closed: Sabin on 19 Dec 2022
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)

Community Treasure Hunt

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

Start Hunting!