symsum of matrix to extract element in the matrix
2 views (last 30 days)
Show older comments
i want to sum this:
The code i used:
syms j
S=[0,1,0,0,0;1/2,0,1/2,0,0;0,1/2,0,1/2,0;0,0,1/2,0,1/2;0,0,0,1,0];
C1=symsum(S(1,j),j,1,5);
The code reterned me error. I want to do the polynomial summation as shwon above. l also would like to extract the element in matrix S for different j. Could you tell me what is the correct code i need to use? Thank you.
0 Comments
Answers (1)
Ameer Hamza
on 10 Jun 2020
Symbolic variables cannot be used as vector index. Also, your data is numeric, and it seems that you want to sum rows. Try this
S = [0,1,0,0,0;1/2,0,1/2,0,0;0,1/2,0,1/2,0;0,0,1/2,0,1/2;0,0,0,1,0];
C1 = sum(S, 2);
If you want to output in symbolic form
S = [0,1,0,0,0;1/2,0,1/2,0,0;0,1/2,0,1/2,0;0,0,1/2,0,1/2;0,0,0,1,0];
C1 = sum(sym(S), 2);
2 Comments
Ameer Hamza
on 10 Jun 2020
Try this
S = [0,1,0,0,0;1/2,0,1/2,0,0;0,1/2,0,1/2,0;0,0,1/2,0,1/2;0,0,0,1,0];
f = @(j) S(1, j);
Result
>> f(1) % j=1 => S11
ans =
0
>> f(2) % j=2 => S12
ans =
1
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!