0% found this document useful (0 votes)
60 views6 pages

Lastsave R

The document contains code for performing matrix operations in R, including creating matrices with values, binding matrices together, and attempting to solve systems of equations. Several errors are encountered, including the system being singular.

Uploaded by

nihad sn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views6 pages

Lastsave R

The document contains code for performing matrix operations in R, including creating matrices with values, binding matrices together, and attempting to solve systems of equations. Several errors are encountered, including the system being singular.

Uploaded by

nihad sn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

> m=matrix(c(3,4,5,6,0,7),nrow=2,byrow=T)

> y=matrix(1:9,nrow=3,byrow=T)
> d=rbind(cbind(3*y,4*y,5*y),cbind(6*y,0*y,7*y))
> d
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 3 6 9 4 8 12 5 10 15
[2,] 12 15 18 16 20 24 20 25 30
[3,] 21 24 27 28 32 36 35 40 45
[4,] 6 12 18 0 0 0 7 14 21
[5,] 24 30 36 0 0 0 28 35 42
[6,] 42 48 54 0 0 0 49 56 63
>
h=matrix(cbind(y*3),cbind(4*y),cbind(5*y),cbind(6*y),cbind(0*y),cbind(7*y),nrow=9,b
yrow=T)
Error in matrix(cbind(y * 3), cbind(4 * y), cbind(5 * y), cbind(6 * y), :
arguments inutilis�s (cbind(6 * y), cbind(0 * y), cbind(7 * y))
> a=matrix(1,ncol=3,nrow=3)
> a
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
> k*solve(a%*%t(a))
Erreur : objet 'k' introuvable
>
h=matrix(cbind(y*3),cbind(4*y),cbind(5*y),cbind(6*y),cbind(0*y),cbind(7*y),nrow=9,b
yrow=T)
Error in matrix(cbind(y * 3), cbind(4 * y), cbind(5 * y), cbind(6 * y), :
arguments inutilis�s (cbind(6 * y), cbind(0 * y), cbind(7 * y))
> 2*solve(a%*%t(a))
Error in solve.default(a %*% t(a)) :
routine Lapack dgesv : le syst�me est exactement singulier : U[2,2] = 0
> x=c(1,2,3)
> y=(4,5,6)
Erreur : ',' inattendu(e) in "y=(4,"
> y=c(4,5,6)
> o=t(x-y)%*%solve(a%*%t(a))%*%(x-y)
Error in solve.default(a %*% t(a)) :
routine Lapack dgesv : le syst�me est exactement singulier : U[2,2] = 0
> o=t(x-y)%*%solve(a%*%t(a))%*%(x-y)
Error in solve.default(a %*% t(a)) :
routine Lapack dgesv : le syst�me est exactement singulier : U[2,2] = 0
> a=matrix(1,ncol=3,nrow=3)
> o=t(x-y)%*%solve(a%*%t(a))%*%(x-y)
Error in solve.default(a %*% t(a)) :
routine Lapack dgesv : le syst�me est exactement singulier : U[2,2] = 0
> t(x-y)%*%solve(a%*%t(a))%*%(x-y)
Error in solve.default(a %*% t(a)) :
routine Lapack dgesv : le syst�me est exactement singulier : U[2,2] = 0
> t(x-y)%*%solve(a%*%t(a))%*%(x-y)
Error in solve.default(a %*% t(a)) :
routine Lapack dgesv : le syst�me est exactement singulier : U[2,2] = 0
> a=matrix(1,nrow)3,byrow=T)
Erreur : unexpected numeric constant in "a=matrix(1,nrow)3"
> a
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
> a=matrix(1,nrow=3,byrow=T)
> x=rep(1,3)
> y
[1] 4 5 6
> y=rep(2,3)
> t(x-y)%*%solve(a%*%t(a))%*%(x-y)
Error in solve.default(a %*% t(a)) :
routine Lapack dgesv : le syst�me est exactement singulier : U[2,2] = 0
> b=matrix(0,nrow=3,ncol=3)
> diag(b)=1
> b
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
> c=matrix(c(2,5,1,3,-10,1,-1,2,-4),nrow=3)
> b=c(4,0,5)
> x=solve(a,b)
Error in solve.default(a, b) : 'a' (3 x 1) doit �tre carr�e
> x=solve(c,b)
> round(x,2)
[1] 1.04 0.34 -0.91
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r
[,1] [,2]
[1,] 48.42434 55.43576
[2,] 53.44068 49.87789
[3,] 52.11854 48.50236
[4,] 47.84879 57.19439
[5,] 50.57504 54.89400
[6,] 53.07028 51.59203
[7,] 47.88153 51.44890
[8,] 50.65136 57.05933
[9,] 48.07778 50.59402
[10,] 53.51885 54.69560
[11,] 48.83834 51.83148
[12,] 51.95464 55.30389
[13,] 48.97717 50.20603
[14,] 51.04525 50.82182
[15,] 52.22467 51.67137
[16,] 50.08241 52.58624
[17,] 50.37909 50.16067
[18,] 49.20966 54.10210
[19,] 49.57369 50.61872
[20,] 48.98304 51.16707
[21,] 50.50774 48.40925
[22,] 46.65730 52.88847
[23,] 47.89392 52.66089
[24,] 51.59003 49.08931
[25,] 48.25876 52.01580
[26,] 52.09361 52.66427
[27,] 52.03711 53.88515
[28,] 49.28707 52.79245
[29,] 50.60304 49.91811
[30,] 48.08013 54.03701
[31,] 50.14173 53.43826
[32,] 52.93509 51.47117
[33,] 50.07113 51.37137
[34,] 48.48524 52.98221
[35,] 48.20659 54.20946
[36,] 50.19564 52.31798
[37,] 52.31581 53.70248
[38,] 50.61846 53.71847
[39,] 51.39322 53.83253
[40,] 48.05041 48.75494
[41,] 51.00183 50.35706
[42,] 49.98474 50.44166
[43,] 50.93098 51.42893
[44,] 50.82766 54.34368
[45,] 48.57058 52.65627
[46,] 51.80728 56.02211
[47,] 47.76142 50.05990
[48,] 48.60777 55.01631
[49,] 49.69334 53.10994
[50,] 52.74725 48.95590
[51,] 49.42473 52.05271
[52,] 50.13349 51.67462
[53,] 51.13802 55.20250
[54,] 52.23380 55.01637
[55,] 50.10606 49.66476
[56,] 48.65839 54.12807
[57,] 51.09347 52.25297
[58,] 47.72222 54.52086
[59,] 49.63202 54.85852
[60,] 48.35678 52.23143
[61,] 52.29803 50.63001
[62,] 50.43060 52.53858
[63,] 50.23434 51.75574
[64,] 49.58442 51.49492
[65,] 47.70808 52.67761
[66,] 48.95306 45.53274
[67,] 52.16926 51.64625
[68,] 49.23112 52.61627
[69,] 50.30968 53.97097
[70,] 49.85694 55.71127
[71,] 50.13721 53.97497
[72,] 51.96465 53.23333
[73,] 47.93898 54.07111
[74,] 52.27184 51.11101
[75,] 50.41892 52.25897
[76,] 48.93194 50.07459
[77,] 50.40756 53.48403
[78,] 48.12345 51.26647
[79,] 54.11107 51.02472
[80,] 49.72164 56.10474
[81,] 50.41016 53.64176
[82,] 50.58678 51.91702
[83,] 51.51920 56.03888
[84,] 50.13161 52.55787
[85,] 49.10416 51.97727
[86,] 50.73753 50.47928
[87,] 53.99488 52.11302
[88,] 48.25354 54.78467
[89,] 50.88044 53.12354
[90,] 48.58994 50.93895
[91,] 49.27814 52.80421
[92,] 51.29932 54.79678
[93,] 49.14066 50.20688
[94,] 47.65388 51.92576
[95,] 48.83932 50.79956
[96,] 47.15448 54.56814
[97,] 49.90518 51.91603
[98,] 49.73136 49.67204
[99,] 51.37479 51.96889
[100,] 48.07807 53.66597
> a=matrix(rep(1:10,10),nrow=10)
> m=a/(t(a))^2
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 0.25 0.1111111 0.0625 0.04 0.02777778 0.02040816 0.015625 0.01234568
[2,] 2 0.50 0.2222222 0.1250 0.08 0.05555556 0.04081633 0.031250 0.02469136
[3,] 3 0.75 0.3333333 0.1875 0.12 0.08333333 0.06122449 0.046875 0.03703704
[4,] 4 1.00 0.4444444 0.2500 0.16 0.11111111 0.08163265 0.062500 0.04938272
[5,] 5 1.25 0.5555556 0.3125 0.20 0.13888889 0.10204082 0.078125 0.06172840
[6,] 6 1.50 0.6666667 0.3750 0.24 0.16666667 0.12244898 0.093750 0.07407407
[7,] 7 1.75 0.7777778 0.4375 0.28 0.19444444 0.14285714 0.109375 0.08641975
[8,] 8 2.00 0.8888889 0.5000 0.32 0.22222222 0.16326531 0.125000 0.09876543
[9,] 9 2.25 1.0000000 0.5625 0.36 0.25000000 0.18367347 0.140625 0.11111111
[10,] 10 2.50 1.1111111 0.6250 0.40 0.27777778 0.20408163 0.156250 0.12345679
[,10]
[1,] 0.01
[2,] 0.02
[3,] 0.03
[4,] 0.04
[5,] 0.05
[6,] 0.06
[7,] 0.07
[8,] 0.08
[9,] 0.09
[10,] 0.10
> n=1/sqrt(abs(a-t(a))+1
+
+ n
Erreur : unexpected symbol in:
"
n"
> n=1/sqrt(abs(a-t(a))+1)
> n
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[,8]
[1,] 1.0000000 0.7071068 0.5773503 0.5000000 0.4472136 0.4082483 0.3779645
0.3535534
[2,] 0.7071068 1.0000000 0.7071068 0.5773503 0.5000000 0.4472136 0.4082483
0.3779645
[3,] 0.5773503 0.7071068 1.0000000 0.7071068 0.5773503 0.5000000 0.4472136
0.4082483
[4,] 0.5000000 0.5773503 0.7071068 1.0000000 0.7071068 0.5773503 0.5000000
0.4472136
[5,] 0.4472136 0.5000000 0.5773503 0.7071068 1.0000000 0.7071068 0.5773503
0.5000000
[6,] 0.4082483 0.4472136 0.5000000 0.5773503 0.7071068 1.0000000 0.7071068
0.5773503
[7,] 0.3779645 0.4082483 0.4472136 0.5000000 0.5773503 0.7071068 1.0000000
0.7071068
[8,] 0.3535534 0.3779645 0.4082483 0.4472136 0.5000000 0.5773503 0.7071068
1.0000000
[9,] 0.3333333 0.3535534 0.3779645 0.4082483 0.4472136 0.5000000 0.5773503
0.7071068
[10,] 0.3162278 0.3333333 0.3535534 0.3779645 0.4082483 0.4472136 0.5000000
0.5773503
[,9] [,10]
[1,] 0.3333333 0.3162278
[2,] 0.3535534 0.3333333
[3,] 0.3779645 0.3535534
[4,] 0.4082483 0.3779645
[5,] 0.4472136 0.4082483
[6,] 0.5000000 0.4472136
[7,] 0.5773503 0.5000000
[8,] 0.7071068 0.5773503
[9,] 1.0000000 0.7071068
[10,] 0.7071068 1.0000000
> var1<-m[,1]
> var2<-n[,1]
> var3<-gl(2,1,length=10,labels=c("b","a"))
> d<-data.frame(var1,var2,var3)
> d
var1 var2 var3
1 1 1.0000000 b
2 2 0.7071068 a
3 3 0.5773503 b
4 4 0.5000000 a
5 5 0.4472136 b
6 6 0.4082483 a
7 7 0.3779645 b
8 8 0.3535534 a
9 9 0.3333333 b
10 10 0.3162278 a
> q()
>

You might also like