To solve a equation in R, you can use solve() function in R. This function takes two main arguments: the coefficients of the equations and the right-hand side values.

The following method shows how you can do it with syntax.

Method 1: Use solve() Function

solve(coefficients, RHS_values)

The following example shows how to use solve() function to solve equation in R.

Using solve() Function

Let’s see how we can use solve() function in R:

# Declare coefficients matrix
coe_mat <- matrix(c(10,3,8,-5,-10,5,7,-10,2), nrow=3,byrow = TRUE)

# Declare right hand side values
v <- c(30,20,10)

# Solve equation
s <- solve(coe_mat,v)

# Print solved equation
print(s)

Output:

[1]  0.09318996 -0.19354839  3.70609319

Here the output shows values of solved equation that we declare in above code.