plotting a function using a function
Show older comments
Hello everyone, I like to ask how do i plot a function that integrates a certain function
Cn = integral(function of the sawtooth * exp(-1i*2*pi*n*f*t), 0, T);
so far this is my working code which only plots the sawtooth wave function. I have made multiple changes to it trying to figure out how to plot Cn. I'm still fairly new to matlab. maybe I'm missing something.
close all; figure; t=linspace(0,3,1500); m=linspace(0,3,1500); T=1; f=1/T; amp=1; sawf=amp/2; k=plot(NaN,NaN); 1i; for n=1:1:500 sawf = sawf - (amp/pi)*(1/n)*(sin(2*pi*n*f*t)); set(k, 'XData',t,'YData',sawf); pause(0.01); end
%cn1= integral(sawf*((cos(2*pi*1*f*t))-(-(1i)*sin(2*pi*1*f*t))),0,T); %cn1= sawf*(sin(2*pi*n*f*t)/(2*pi*n*f))+((i)cos(2*pi*n*f*t)/(2*pi*n*f)); %cn = (1./T)*cn1; %set(k, 'XData',m,'YData',cn);
3 Comments
Dyuman Joshi
on 9 Sep 2023
Edited: Dyuman Joshi
on 9 Sep 2023
integral requires a function handle as an integrand. You have not supplied any function, just a numerical value.
Also, I don't understand how this -
%1
cn1= integral(sawf*((cos(2*pi*1*f*t))-(-(1i)*sin(2*pi*1*f*t))),0,T);
results in this -
%2
cn1= sawf*(sin(2*pi*n*f*t)/(2*pi*n*f))+((i)cos(2*pi*n*f*t)/(2*pi*n*f));
or how did you arrive at line 2.
or was it supposed to be n instead of 1 (next to pi inside the trignometric terms) in line 1?
jvfa
on 9 Sep 2023
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







