例7-23 矩阵和数组的幂运算。
解:在命令窗口中输入如下命令,并按Enter键确认。
>> p=sym('[x,1/x,x^2,x^3;a,b,c,d;1,2,3,7]')
p =
[ x, 1/x, x^2, x^3]
[ a, b, c, d]
[ 1, 2, 3, 7]
>> q=sym('[2,4,9,5;x,y,z,w;a,b,c,d;4 3 5 8]')
q =
[ 2, 4, 9, 5]
[ x, y, z, w]
[ a, b, c, d]
[ 4, 3, 5, 8]
>> q^2
ans =
[ 24+4*x+9*a, 23+4*y+9*b, 43+4*z+9*c, 50+4*w+9*d]
[ 2*x+y*x+z*a+4*w, 4*x+y^2+z*b+3*w, 9*x+y*z+z*c+5*w, 5*x+y*w+z*d+8*w]
[ 2*a+b*x+c*a+4*d, 4*a+b*y+c*b+3*d, 9*a+z*b+c^2+5*d, 5*a+b*w+c*d+8*d]
[ 40+3*x+5*a, 40+3*y+5*b, 76+3*z+5*c, 84+3*w+5*d]
>> p^2
??? Error using ==> sym/mpower
Matrix must be square.
>>