I'm trying to write a script for the sum of the $j$-th powers of the first $n$ numbers in MATLAB, so:
$s(n,j) = 1+2^j+3^j+\cdots +n^j$
The function should have two inputs so I have started with:
% Sum of the j-th powers of the first n numbers
function z = sumofpowers(n,j)
y=zeros(1,n); y(1)=1;
for
Then I am stuck on how to actually write this function in MATLAB.
Can someone help?
EDIT:
This is my full code:
% Sum of the j-th powers of the first n numbers
function z = sumofpowers(n,j)
y=zeros(1,n);
y(1)=1;
for y=2:n
end
z = sum(y.^j)
function z = sumofpowers(n,j)
y=zeros(1,n); y(1)=1;
for y=2:n
end
z = sum(y.^j)
– Edward Nov 04 '13 at 12:11for k=1:n, y(k) = k; end; z = sum(y.^j)– Adriano Nov 04 '13 at 18:35