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

(R) Error in solve() 'a' must be a numeric matrix

问题来了:我想计算 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、T3 和 T4 替换为 50,因为我需要多次重新计算以更改 T2、T3 和 T4 值。

正如错误信息所说。 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"))

等计算数值