How to add matrix in a matrix which is obtained using syms function?
Show older comments
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.
Accepted Answer
More Answers (1)
Paul
on 25 Apr 2021
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 Comments
Walter Roberson
on 25 Apr 2021
blkdiag(ones(3,'sym'),pi*ones(2,'sym'))
works
Steven Lord
on 25 Apr 2021
If a function only uses operations and functions that are supported for a data type, those functions can work for that data type even if there is no specific implementation of that function for that type.
For the case of blkdiag, the code path in blkdiag.m that sym arrays follow require size, zeros, and concatenation to be defined for sym in order to work. Since the sym type does define those functions / operations the general implementation of blkdiag.m can work on sym arrays.
Paul
on 25 Apr 2021
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
on 25 Apr 2021
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.
Categories
Find more on Logical 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!