I have a summation loop which is within a nested loop to generate a matrix. I'm not sure how to make it work properly for a start, and then only fill cells which are not on row 1, or column 1.

The code so far is

close all

clear

clc

n = 5;

n_pot = 5;

Vec = [1,1,1,1,1,1,1]

syms k

Sum = sum(Vec,1:n)

Vt = zeros(1,n);

V_sum = zeros(1,n);

A = zeros(n);

for rows = 1:n

for cols = 1:n

for i = 1:n_pot

Vt(i) = Vt(i) + (Vec(i)*(Kron(rows+cols,i) + Kron(abs(cols-rows),i)));

V_sum = Vt(i);

A(rows,cols) = V_sum

end

end

end

function d = Kron(k,j)

if k == j

d = 1;

else

d = 0;

end

end

The Vec vector is only there for ease of manipulation on my part and will be replaced with a regular vector from graph fitting data.

The matrix I'm expecting to get is of the form

Matrix = / / / / /

/ / Vec(1)+Vec(3) Vec(2)+Vec(3) Vec(3)+Vec(5)

/ Vec(1)+Vec(3) / Vec(1)+Vec(5) Vec(2)+Vec(6)

/ Vec(2)+Vec(3) Vec(1)+Vec(5) / Vec(1)

/ Vec(3)+Vec(5) Vec(2)+Vec(6) Vec(1) /

Following this equation, I'm looking to implement the summation portion, and the first term is already worked in.