Solve Linear Algebraic Equation in R Programming – solve() Function
Last Updated :
25 Jun, 2020
solve()
function in R Language is used to solve linear algebraic equation. Here equation is like a*x = b, where b is a vector or matrix and x is a variable whose value is going to be calculated.
Syntax: solve(a, b)
Parameters:
a: coefficients of the equation
b: vector or matrix of the equation
Example 1:
solve( 5 , 10 )
solve( 2 , 6 )
solve( 3 , 12 )
|
Output:
[1] 2
[1] 3
[1] 4
Example 2:
a1 < - c( 3 , 2 , 5 )
a2 < - c( 2 , 3 , 2 )
a3 < - c( 5 , 2 , 4 )
A < - rbind(a1, a2, a3)
print (A)
T1 < - solve(A)
print (T1)
|
Output:
[, 1] [, 2] [, 3]
a1 3 2 5
a2 2 3 2
a3 5 2 4
a1 a2 a3
[1, ] -0.29629630 -0.07407407 0.4074074
[2, ] -0.07407407 0.48148148 -0.1481481
[3, ] 0.40740741 -0.14814815 -0.1851852
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...