Using sigma notation when index is included in fucntion
2 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Steven Lord
on 4 Dec 2020
There's no need to use symsum here. The sum function will be sufficient.
A = diag([1 2 4 8])
D = eig(A)
s = sum(1./D) % The . is important to perform elementwise division
15/8 % 1 + 1/2 + 1/4 + 1/8
0 Comments
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!