MATLAB: How to write m file

homeworkm-file

I need help writing a m file function. Any pointers would be great. Thank you.

Best Answer

There are so many ways to do this. Probably the easiest way for a beginner is the for loop way. Hint:
for tIndex = 1 : length(t)
theSum = a(1);
for k = 2 : length(a)-1
theSum = theSum + a(k) * cos((k-1)*t(tIndex)) + b(k) * sin((k-1)*t(tIndex));
end
y(tIndex) = %%%%%%%%%%% You have to do something to finish your homework
end
Since it's your homework I probably did too much for you, but I didn't do it 100% so at least you can claim some small part as your own.