MATLAB里用syms定义了符号变量,赋值给矩阵就不行了吗,为什么会出这样的错
2个回答
展开全部
去掉 t=zeros(10);
下面是正确的代码:
syms t1 t2 t3 t4 t5 t6 t7 t8 t9 t10;
t(1,1)=t1;
t(2,2)=t2;
t(3,3)=t3;
t(4,4)=t4;
t(5,5)=t5;
t(6,6)=t6;
t(7,7)=t7;
t(8,8)=t8;
t(9,9)=t9;
t(10,10)=t10;
代码写得更简洁一些的话,就使用diag命令,它用于创建对角矩阵:
>> syms t1 t2 t3 t4 t5 t6 t7 t8 t9 t10;
>> t=diag([t1 t2 t3 t4 t5 t6 t7 t8 t9 t10])
t =
[ t1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[ 0, t2, 0, 0, 0, 0, 0, 0, 0, 0]
[ 0, 0, t3, 0, 0, 0, 0, 0, 0, 0]
[ 0, 0, 0, t4, 0, 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, t5, 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0, t6, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0, 0, t7, 0, 0, 0]
[ 0, 0, 0, 0, 0, 0, 0, t8, 0, 0]
[ 0, 0, 0, 0, 0, 0, 0, 0, t9, 0]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, t10]
希望对你有帮助。欢迎交流!
下面是正确的代码:
syms t1 t2 t3 t4 t5 t6 t7 t8 t9 t10;
t(1,1)=t1;
t(2,2)=t2;
t(3,3)=t3;
t(4,4)=t4;
t(5,5)=t5;
t(6,6)=t6;
t(7,7)=t7;
t(8,8)=t8;
t(9,9)=t9;
t(10,10)=t10;
代码写得更简洁一些的话,就使用diag命令,它用于创建对角矩阵:
>> syms t1 t2 t3 t4 t5 t6 t7 t8 t9 t10;
>> t=diag([t1 t2 t3 t4 t5 t6 t7 t8 t9 t10])
t =
[ t1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[ 0, t2, 0, 0, 0, 0, 0, 0, 0, 0]
[ 0, 0, t3, 0, 0, 0, 0, 0, 0, 0]
[ 0, 0, 0, t4, 0, 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, t5, 0, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0, t6, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0, 0, t7, 0, 0, 0]
[ 0, 0, 0, 0, 0, 0, 0, t8, 0, 0]
[ 0, 0, 0, 0, 0, 0, 0, 0, t9, 0]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, t10]
希望对你有帮助。欢迎交流!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询