symsum of matrix to extract element in the matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Ameer Hamza
el 10 de Jun. de 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 comentarios
Ameer Hamza
el 10 de Jun. de 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
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!