Matlab Sum Sign Inside for Loop

I am trying to implement the following loop inside of matlab

The difficulty I am having is implementing the sum sign such that I get the correct values. The first row of my X matrix is correct but the second row is not and I cant figure out why.

J = [200 100 300];
k = [3e6 2e6 4e6];

n = 3;
points = 300;

for j = 1:points
    w(j)=j;
end

x = zeros(n+1,points);
x(1,:)=1;
for j = 1:points
    sumJx = 0;
    for i = 2:n+1
        sumJx = sum(J(1:i-1)*x(1:i-1,j));
        x(i,j) = x(i-1) - (w(j)^2 / k(i-1)) * sumJx;   
    end
end
f_omega = x(n+1,:);
plot(w,f_omega);
ylim([-40 3])
1
Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article