Ask your own question, for FREE!
Mathematics 18 Online
OpenStudy (anonymous):

im trying to plot a graph in matlab for a fourier series f(t) = 1 - t^2 -1

jimthompson5910 (jim_thompson5910):

you state that term = cos(pi*x*n)*(2)*((-1)^(n-1))/(pi*n)^2; but x is not defined So Matlab has no idea what to do with it

jimthompson5910 (jim_thompson5910):

you probably mean term = cos(pi*t*n)*(2)*((-1)^(n-1))/(pi*n)^2;

jimthompson5910 (jim_thompson5910):

oh and t is a vector so t^2 doesn't make any sense

jimthompson5910 (jim_thompson5910):

type t.^2 instead to tell Matlab to square each element of this vector separately

OpenStudy (anonymous):

i added the '.' and changed the variable to 't' and it now plots a parabola :) the question also says to plot on the same axis when N=6 but when i change the value of N the graph stays the same

jimthompson5910 (jim_thompson5910):

that's because the first graph doesn't depend on N

jimthompson5910 (jim_thompson5910):

notice how you have sumCos, but it's defined by itself but there's nothing defined for it beforehand

jimthompson5910 (jim_thompson5910):

how does sumCos start?

OpenStudy (anonymous):

i added some code so now its like this, N=3; t=-1:.01:1; y=1-(t.^2); plot(t,y) axis([-1 1 0 1]) hold on kmax = floor((N-1)/2); sumCos = 0; sumSin = 0; for n=1:N term = cos(pi*t*n)*(2)*((-1)^(n-1))/(pi*n)^2; sumCos = sumCos + term; end f = (2/3) + sumCos; plot(t,f) i dont know what the bit i added means though (sorry im not very good at matlab) they just included that in one of the examples so i thought i should try it

jimthompson5910 (jim_thompson5910):

ok, that does compile and run correctly (or at least a plot comes up)

jimthompson5910 (jim_thompson5910):

this is what comes up

OpenStudy (anonymous):

yeh that is what i got also, should N=6 give a closer approximation?

jimthompson5910 (jim_thompson5910):

it looks like it's approaching 1-t^2, but I'm not really familiar with fourier series

OpenStudy (anonymous):

thats ok, thank you so much for all of your help :)

jimthompson5910 (jim_thompson5910):

np

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!