I'm trying to write a function that calculates sum of ((-1)^k *sin((2k+1)t))/((2k+1)^2 ( for k=0 to n) t varies from 0 to 4*pi with 1001 values its supposed to return a vector with size n this is the code i wrote
function [summ ]= triangle_wave (n) for k=1:n; for t= linspace(0,4*pi,1001); summ=sum((-1)^k*sin((2*k+1)*t))/((2*k+1)^2); end end end
it keeps outputting the last calculate sum instead of adding each sum to the vector . what can i add to this code to achieve that ?
Best Answer