Why does my program not graph my function (line 17)?
Show older comments
t = [-2:.001:2];
y = 0.5*square(2*pi*t,50)+0.5;
plot(t,y);
xlabel('Time');
title('Square wave with 50% duty cycle Marcial');
grid on;
axis([-2 2 -1 2]);
x0=.5;
syms n t;
h1 = x0 + (1-cos(pi)*(sin(2*pi*t))/pi); %1st harmonic
h3 = x0 + symsum((1-cos(pi*n)*(sin(2*pi*t))/pi*n),n,1,3); %third harmonic
h5 = x0 + symsum((1-cos(pi*n)*(sin(2*pi*t))/pi*n),n,1,5); %fifth harmonic
h7 = x0 + symsum((1-cos(pi*n)*(sin(2*pi*t))/pi*n),n,1,7); %seventh harmonic
h20 = x0 + symsum((1-cos(pi*n)*(sin(2*pi*t))/pi*n),n,1,20); %20th harmonic
h100 = x0 + symsum((1-cos(pi*n)*(sin(2*pi*t))/pi*n),n,1,100); %100th harmonic
hold on;
plot(t,h1);
I am trying to approximate a square wave with it's fourier series. The final line is giving me an error: "Data must be numeric, datetime, duration or an array convertible to double." I am not sure what this means. I have attempted to plot both the square wave and the function h1 using the same line (and subsequent plotting data after calculating harmonics), but that does not work either. Thank you for your time.
Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!