R語(yǔ)言奶甘,免費(fèi),功能強(qiáng)大臭家,想你所想吭产,助你展翅翱翔鸭轮!
1.在求解矩陣方程之前,先弄明白如何用R語(yǔ)言表明矩陣邑蒋?
簡(jiǎn)單按厘,用Matrix(),請(qǐng)看:
1.1簡(jiǎn)單的2*2矩陣:
> matrix(c(2,3,4,5),nrow=2,byrow=T)
????[,1] [,2]
[1,]???2??? 3
[2,]???4??? 5
1.2 現(xiàn)來(lái)看看如何呈現(xiàn)Hilbert矩陣:
Hilbert矩陣是一種n階方陣,其第m行逮京,第n列處的元素為 1/(m+n-1)。
如何輸出6階Hilbert矩陣:
hh即為6階Hilbert矩陣
> m=matrix(rep(1:6,each=6),nrow=6)
> m
????[,1] [,2] [,3] [,4] [,5] [,6]
[1,]???1??? 2??? 3???4??? 5??? 6
[2,]???1??? 2??? 3???4??? 5??? 6
[3,]???1??? 2??? 3???4??? 5??? 6
[4,]???1??? 2???3??? 4??? 5??? 6
[5,]???1??? 2??? 3???4??? 5??? 6
[6,]???1??? 2??? 3???4??? 5??? 6
>n=matrix(rep(1:6,each=6),nrow=6,byrow=T)
> n
????[,1] [,2] [,3] [,4] [,5] [,6]
[1,]???1??? 1??? 1???1??? 1??? 1
[2,]???2??? 2???2??? 2??? 2??? 2
[3,]???3??? 3??? 3???3??? 3??? 3
[4,]???4??? 4??? 4???4??? 4??? 4
[5,]???5??? 5??? 5???5??? 5??? 5
[6,]???6??? 6??? 6???6??? 6??? 6
> hh<-1/(m+n-1)
> hh
????????? [,1]????? [,2]?????[,3]????? [,4]????? [,5]??????[,6]
[1,] 1.0000000 0.5000000 0.33333330.2500000 0.2000000 0.16666667
[2,] 0.5000000 0.3333333 0.25000000.2000000 0.1666667 0.14285714
[3,] 0.3333333 0.2500000 0.20000000.1666667 0.1428571 0.12500000
[4,] 0.2500000 0.2000000 0.16666670.1428571 0.1250000 0.11111111
[5,] 0.2000000 0.1666667 0.14285710.1250000 0.1111111 0.10000000
[6,] 0.1666667 0.1428571 0.12500000.1111111 0.1000000 0.09090909
2.如何求逆矩陣:
用solve()求逆矩陣览绿,TT即為tt的逆矩陣穗慕。
>tt<-matrix(c(2,3,4,5),nrow=2,byrow=T)
> tt
????[,1] [,2]
[1,]???2??? 3
[2,]???4??? 5
> TT<-solve(tt)
> TT
????[,1] [,2]
[1,] -2.5? 1.5
[2,]?2.0 -1.0
3.如何求形如AX=b的矩陣方程:
也用solve()求:
> A
????[,1] [,2]
[1,] -2.5? 1.5
[2,]?2.0 -1.0
> b=matrix(c(2,1),nrow=2)
> b
????[,1]
[1,]???2
[2,]???1
> x<-solve(A,b)
> x
????[,1]
[1,]???7
[2,]??13
平時(shí),用筆求逆矩陣怀各,求解矩陣术浪, 是不是沒(méi)動(dòng)筆,就先撓頭沥曹?其實(shí)是太費(fèi)時(shí)太傷腦筋了碟联,心里一萬(wàn)匹草泥馬!
何不讓R語(yǔ)言來(lái)幫幫你鲤孵,輕松快速搞定!
歡迎小伙伴們點(diǎn)贊收藏F占唷贵试!