(R)solve()中的错误'a'必须是数字矩阵

时间:2016-06-03 02:58:36

标签: r inversion rgui

问题在于:我想计算3x3矩阵的倒数。我尝试使用solve(J),但它给出了一条错误消息:

solve.default(J)中的错误:'a'必须是数字矩阵。

这是矩阵J和代码:

T1<-20
T2<-50
T3<-50
T4<-50
T5<-350

        df1dx1<- Deriv(-(14.6+0.0635*(T2+T1))*T2-(14.6+0.0635*(T2+T1))*T1+(14.6+0.0635*(T3+T2))*T3-(14.6+0.0635*(T3+T2))*T2, "T2")
        df1dx2<- Deriv(-(14.6+0.0635*(T2+T1))*T2-(14.6+0.0635*(T2+T1))*T1+(14.6+0.0635*(T3+T2))*T3-(14.6+0.0635*(T3+T2))*T2, "T3")
        df1dx3<- Deriv(-(14.6+0.0635*(T2+T1))*T2-(14.6+0.0635*(T2+T1))*T1+(14.6+0.0635*(T3+T2))*T3-(14.6+0.0635*(T3+T2))*T2, "T4")
        df2dx1<- Deriv(-(14.6+0.0635*(T3+T2))*T3-(14.6+0.0635*(T3+T2))*T2+(14.6+0.0635*(T4+T3))*T4-(14.6+0.0635*(T4+T3))*T3,"T2")
        df2dx2<- Deriv(-(14.6+0.0635*(T3+T2))*T3-(14.6+0.0635*(T3+T2))*T2+(14.6+0.0635*(T4+T3))*T4-(14.6+0.0635*(T4+T3))*T3,"T3")
        df2dx3<- Deriv(-(14.6+0.0635*(T3+T2))*T3-(14.6+0.0635*(T3+T2))*T2+(14.6+0.0635*(T4+T3))*T4-(14.6+0.0635*(T4+T3))*T3,"T4")
        df3dx1<- Deriv(-(14.6+0.0635*(T4+T3))*T4-(14.6+0.0635*(T4+T3))*T3+(14.6+0.0635*(T5+T3))*T5-(14.6+0.0635*(T5+T4))*T4,"T2")
        df3dx2<- Deriv(-(14.6+0.0635*(T4+T3))*T4-(14.6+0.0635*(T4+T3))*T3+(14.6+0.0635*(T5+T3))*T5-(14.6+0.0635*(T5+T4))*T4,"T3")
        df3dx3<- Deriv(-(14.6+0.0635*(T4+T3))*T4-(14.6+0.0635*(T4+T3))*T3+(14.6+0.0635*(T5+T3))*T5-(14.6+0.0635*(T5+T4))*T4,"T4")

    J<-matrix(c(df1dx1,df1dx2,df1dx3,df2dx1,df2dx2,df2dx3,df3dx1,df3dx2,df3dx3),nrow=3,ncol=3,byrow=TRUE)

invJ<- solve(J)  ##this gives the problem

有什么问题?非常感谢你们。 Obs:我不能用T2代替T2,T3和T4,因为我需要多次重新计算这个,改变T2,T3和T4值。

1 个答案:

答案 0 :(得分:0)

正如错误消息所示。 solve需要一个数字矩阵,但是你已经在表达式矩阵中给出了。你可以做到

eval(Deriv(-(14.6+0.0635*(T2+T1))*T2-(14.6+0.0635*(T2+T1))*T1+(14.6+0.0635*(T3+T2))*T3-(14.6+0.0635*(T3+T2))*T2, "T2"))

等。计算数值