How to add matrix in a matrix which is obtained using syms function?
조회 수: 2 (최근 30일)
이전 댓글 표시
B1 =
[ 0, conj(eta)/24 - 1/24, (3*conj(xi))/160 - 3/160]
[ 0, conj(eta)/80 - 1/80, conj(xi)/16 - 1/16]
[ 0, (7*conj(xi))/320 - 7/320, (7*conj(eta))/480 - 7/480]
B2 =
[ 0, 1/24 - conj(eta)/24, - (3*conj(xi))/160 - 3/160]
[ 0, 1/80 - conj(eta)/80, - conj(xi)/16 - 1/16]
[ 0, - (7*conj(xi))/320 - 7/320, 7/480 - (7*conj(eta))/480]
These are the value of B1 and B2 which are obtained using syms function. I have to add matrix B1 and B2 in a 6x6 matrix named B. How can I do this. I tried the following code but it doesn't work.
B=zeros(6);
B([1:3],[1:3])=B1;
B([4:6],[4:6])=B2;
With this code, I obtain the following error.
The following error occurred converting from sym to double: DOUBLE cannot convert the input expression into a double array.
Please help me to combine the following matrix as required.
댓글 수: 0
채택된 답변
Walter Roberson
2018년 9월 13일
B=sym(zeros(6));
댓글 수: 2
Walter Roberson
2021년 4월 25일
Yes, that will work on all versions of MATLAB that have supported the Symbolic Mathworks toolbox, including the original Maple based Symbolic Toolbox.
Also in sufficiently new versions of MATLAB you can
B = zeros(6,'sym');
I would need to research which version that was supported from. I think it was R2011b, but I am not certain.
추가 답변 (1개)
Paul
2021년 4월 25일
blkdiag() seems to work
blkdiag(B1,B2)
though interestingly enough it appears that blkdiag is not a supported function for the Symbolic Math Toolbox
댓글 수: 4
Paul
2021년 4월 25일
Thank you for that clarification.
Is there a way to determine if a function will work for a sym object (or any other object, come to think of it), other than code inspection or just trying it?
Walter Roberson
2021년 4월 25일
Not really. You can use methods() on a sym object, but that is only for specific implementations. You can
which blkdiag(sym('x'))
But arguably that is equivalent to just trying it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!