필터 지우기
필터 지우기

symsum of matrix to extract element in the matrix

조회 수: 2 (최근 30일)
Penglin Cai
Penglin Cai 2020년 6월 10일
댓글: Ameer Hamza 2020년 6월 10일
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.

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 6월 10일
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
Penglin Cai
Penglin Cai 2020년 6월 10일
Thank you for the answer. But I do not want to sum the rows, l want to extract certain element in the matrix for different j. For example, i want to S11 for j=1, S12 for j=2.
Ameer Hamza
Ameer Hamza 2020년 6월 10일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by