You are on page 1of 6

Abhinav Arora (08) 1714110101

Aim:

Theory:
Linear Equation:

Linear equation is an algebraic equation in which each term has an exponent of one and the graphing
of the equation results in a straight line.

Linear equations are equations of the first order. These equations are defined for lines in the
coordinate system. An equation for a straight line is called a linear equation. The general
representation of the straight-line equation is y=mx+b, where m is the slope of the line and b is the y-
intercept.
There are three types of linear equations.
 Slope-Intercept Form
 Point-Slope Form
 Standard Form

Slope–Intercept Form:
y = mx + b
where m is the slope of the line and b is the y-intercept.
The y-intercept is the y-coordinate of the location where line crosses the y axis. This is the point when
x = 0 and y = b.
Vertical lines, having undefined slope, cannot be represented by this form.
The slope-intercept form is useful when we are given the slope and y-intercept of a line and we need
to write an equation for the line.
It is also useful because we can read the slope and y-intercept from the equation. Often, when we are
given equations in other forms, we can rewrite it in slope-intercept form to get the slope and y-
intercept.
The slope-intercept form is also useful when we need to draw the line on a graph.
Abhinav Arora (08) 1714110101

Point-Slope Form

y − y1 = m(x − x1)
where m is the slope of the line and (x1, y1) is any point on the line.
The point-slope form shows that the difference in the y-coordinate between two points on a line is
proportional to the difference in the x coordinate. The proportionality constant is the slope of the line, m.
The point-slope form is useful when we are given a point on a line and the slope and we need to get the
equation of the line.

Standard Form:

Ax + By = C
where A or B can be zero, but not both at the same time. A, B and C are integers and A ≥ 0. A, B and C
have no common factors other than 1.
This Form is used when we want to solve systems of linear equations.
When we want to write equations for vertical lines which is not possible in slope-intercept form or
point-slope form.

Steps to solve Linear Equations using matrices:

1. Write the augmented matrix for the linear equations.


2. Use elementary row operations on the augmented matrix [A|b] to transform A to upper triangle
form. If a zero is on the diagonal, switch the rows until a nonzero is in its place.
3. Use back substitution to find the solution.

Solve() in R:
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
Abhinav Arora (08) 1714110101

Input:
Step 1: Initialize a matrix A using matrix() function and assign the values to it. For Ax = y

> A<-matrix(c(1,2,3,4,5,2,1,2,3,4,3,2,1,2,3,4,3,2,1,2,5,4,3,2,1),nrow=5,byrow=TRUE)
>A
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 2 1 2 3 4
[3,] 3 2 1 2 3
[4,] 4 3 2 1 2
[5,] 5 4 3 2 1
>
Abhinav Arora (08) 1714110101

Step 2: Initialize a matrix y using matrix() function and assign the values to it.

> y<-matrix(c(7,-1,-3,5,17))
>y
[,1]
[1,] 7
[2,] -1
[3,] -3
[4,] 5
[5,] 17
>
Abhinav Arora (08) 1714110101

Step 3: Use solve() to find the solution for matrices and value for x in Ax = y

> solve(A,y)
[,1]
[1,] -2
[2,] 3
[3,] 5
[4,] 2
[5,] -4
>
Abhinav Arora (08) 1714110101

Inputs:

Output:

You might also like