An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050525/1a09c23a/attachment.pl
Linear system
4 messages · Jim Gustafsson, Uwe Ligges, Sundar Dorai-Raj +1 more
Jim Gustafsson wrote:
Dear R-help I have a problem solving a linear system like 353a+45b+29c=79 45a+29b+3c=5 29a+3b+4c=8
>
Is there any way of doing this in R?
You already said it yourself ("solve"):
A <- rbind(c(353, 45, 29), c(45, 29, 3), c(29, 3, 4))
solve(A, c(79, 5, 8))
# [1] 0.1784625 -0.1924954 0.8505186
Uwe Ligges
Best Regards Jim ------------------------------------------------------------------------------ This e-mail and any attachment may be confidential and may also be privileged. If you are not the intended recipient, please notify us immediately and then delete this e-mail and any attachment without retaining copies or disclosing the contents thereof to any other person. Thank you. ------------------------------------------------------------------------------ [[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Jim Gustafsson wrote:
Dear R-help I have a problem solving a linear system like 353a+45b+29c=79 45a+29b+3c=5 29a+3b+4c=8 Is there any way of doing this in R? Best Regards Jim
Use ?solve:
X <- matrix(c(353, 45, 29,
45, 29, 3,
29, 3, 4), 3, 3, byrow = TRUE)
y <- c(79, 5, 8)
b <- solve(X, y)
Have you read the posting guide? In particular, have you tried simple
queries using help.search or the R archives? This question has been
answered many times.
HTH,
--sundar
On Wednesday 25 May 2005 14:30, Jim Gustafsson wrote:
Dear R-help I have a problem solving a linear system like 353a+45b+29c=79 45a+29b+3c=5 29a+3b+4c=8 Is there any way of doing this in R?
You can write this equation system in matrix form:
M * x = y
with
x = ( a, b, c )
M = ( 353, 45, 29,
45, 29, 3,
29, 3, 4 )
y = ( 79, 5, 8 )
you can solve the system by
x = M^(-1) * y
In R you can do this by
R> M = matrix( c( 353, 45, 29, 45, 29, 3, 29, 3, 4 ),
ncol = 3, byrow = TRUE )
R> y <- c( 79, 5, 8 )
R> x <- solve( M ) %*% y
or
R> x <- solve( M, y )
Please read a basic book about linear algebra.
Arne
Best Regards Jim --------------------------------------------------------------------------- --- This e-mail and any attachment may be confidential and may also be privileged. If you are not the intended recipient, please notify us immediately and then delete this e-mail and any attachment without retaining copies or disclosing the contents thereof to any other person. Thank you. --------------------------------------------------------------------------- --- [[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 ahenningsen at agric-econ.uni-kiel.de http://www.uni-kiel.de/agrarpol/ahenningsen/