Using sigma notation when index is included in fucntion

2 vues (au cours des 30 derniers jours)
Sam Shrift
Sam Shrift le 4 Déc 2020
I am fairly new to MATLAB, so I apologize if I am not able to explain everything perfectly. Im am trying to use the sum of a series function to compute the Kirchhoff index of a network. The formula in question looks like this:
The code I am using contains the symsum fucntion. However, the function for the sigma notation includes the eigenvalue, which in my code is stored in a 4x1 double. To add the inverse of the eignevalues, I have to index from 2 to 4 within the sigma notation. Because of this, the index (i) for my sigma notation is included in the formula, which gives an error. My code is as follows:
%% Problem 2
% Computation of Laplacian Eigenvalues
L_a = [3, -1, -1, -1 ; -1, 3, -1, -1 ; -1, -1, 3, -1 ; -1, -1, -1, 3];
L_b = [0, 0, 0, 0 ; 0, 0, 0, 0 ; 0, 0, 0, 0 ; 0, 0, 0, 0];
L_c = [2, -1, 0, -1 ; -1, 2, -1, 0 ; 0, -1, 2, -1 ; -1, 0, -1, 2];
L_d = [1, -1, 0, 0 ; -1, 3, -1, -1 ; 0, -1, 1, 0 ; 0, -1, 0, 1];
L_e = [1, -1, 0, 0 ; -1, 2, -1, 0 ; 0, -1, 2, -1 ; 0, 0, -1, 1];
eigL_a = eig(L_a);
eigL_b = eig(L_b);
eigL_c = eig(L_c);
eigL_d = eig(L_d);
eigL_e = eig(L_e);
% Computing the Kirchhoff index (total effective reistance)
syms i
R_a = 4*symsum(1/eigL_a(i),i,2,4)
The resulting error looks like this:
Is there any way to work around this while still using the symsum formula, or possibly a for loop? Otherwise, is there an easier way to compute this sigma notation in MATLAB?
Any help would be greatly appreciated.

Réponses (1)

Steven Lord
Steven Lord le 4 Déc 2020
There's no need to use symsum here. The sum function will be sufficient.
A = diag([1 2 4 8])
A = 4×4
1 0 0 0 0 2 0 0 0 0 4 0 0 0 0 8
D = eig(A)
D = 4×1
1 2 4 8
s = sum(1./D) % The . is important to perform elementwise division
s = 1.8750
15/8 % 1 + 1/2 + 1/4 + 1/8
ans = 1.8750

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by