# Solving System of Equations in R With Example

In this article, we will discuss solving a system of equations in the R Programming Language. solve() function in R Language is used to solve the 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: Solving system equation of three equations

```Given Equations:
x + 2y + 3z = 20
2x + 2y + 3z = 100
3x + 2y + 8z = 200

Matrix A and B for solution using coefficient of equations:
A->
1   2   3
2   2   3
3   2   8
B->
20
100
200```

To solve this using two matrices in R we use the following code:

``````# create matrix A and B using given equations
A <- rbind(c(1, 2, 3),
c(2, 2, 3),
c(3, 2, 8))
B <- c(20, 100, 200)

# Solve them using solve function in R
solve(A, B)
``````

Output:

`80 -36 3.99999999999999`

## Example 2: Solving system equation of three equations

To get solutions in form of fractions, we use the library MASS in R Language and wrap solve function in fractions.

```Given Equations:
19x + 32y + 31z = 1110
22x + 28y + 13z = 1406
31x + 12y + 81z = 3040
Matrix A and B for solution using coefficient of equations:
A->
19   32   31
22   28   13
31   12   81
B->
1110
1406
3040```

To solve this using two matrices in R we use the following code:

• R
``````# Load package MASS
library(MASS)

# create matrix A and B using given equations
A <- rbind(c(19, 32, 31),
c(22, 28, 31),
c(31, 12, 81))
B <- c(1110, 1406, 3040)

# Solve them using solve
# function wrapped in fractions
fractions(solve(A, B))
``````

Output:

` 159950/2243 -92039/4486  29784/2243 which means x=159950/2243 , y=-92039/4486 and z=29784/2243 is the solution for the above given linear equation.`

## Example 3: Solving Inverse matrix

• R
``````# create matrix A and B using given equations
A <- matrix(c(4, 7, 3, 6), ncol = 2)
print(A)

print("Inverse matrix")

# Solve them using solve function in R
print(solve(A))
``````

Output:

```     [,1] [,2]
[1,]    4    3
[2,]    7    6
 "Inverse matrix"
[,1]      [,2]
[1,]  2.000000 -1.000000
[2,] -2.333333  1.333333```

Related post: R PROGRAMMING MADE EASY

### 5 thoughts on “Solving System of Equations in R With Example”

1. Turbanli annem’ Search, free sex videos. Language ; Content ;
TURBANLI TURK. 1.2M 100% 20min 480p. Real Amateur Porn 1.
Mi sono fatto travolgere dalla passione e mi sono scopato mia madre Terry.
2.4k 81% 32min 720p.

2. Yalamalık sik bu diyor kız yumuluyor Evliki iyi gitmeyince kendine
başka sikici İnşaat mühendisi liseli kizi şantiyede sikiyor dikkat liseli çıkabilir.

3. Hiya very nice website!! Guy .. Excellent ..

Superb .. I will bookmark your website and take the feeds also?

I’m glad to seek out a lot of helpful information right here in the put up,
we need develop more strategies on this regard,
thanks for sharing. . . . . .

4. Güzel asyalı genç tomoyo i̇sumi bir yaşlı adam tarafından becerdin ve creampied
alır. Baba ve kızı seks full: bit ly watchxms001.
ağızda döl 69 döl sert. Güzel japon genç onu sıkı bal delik sert
becerdin alır. olgun ve gen.

5. 