plot_lines: Plot the Lines of the Matrix of a System of Equations

Description Usage Arguments Value Examples

View source: R/plot_lines.R

Description

This function plots the system of equations represented by a matrix. For each row, it plots a line representing every possible two-dimensional vector that would satisfy the equation.

Usage

1
plot_lines(m, b = rep(0, nrow(m)), colors = grDevices::rainbow(n = nrow(m)))

Arguments

m

An n x 2 matrix representing a system of equations in n dimensions

b

An n x 1 matrix or atomic vector representing the solutions to the equations of m. If omitted, a vector of n 0s is used, as in a homogeneous system of equations

colors

Optional vector of colors for the lines, one for each equation in m, reading downward. If not provided, colors are chosen automatically. If shorter than b, it is recycled per R's usual rules. If longer, extra colors are ignored.

Value

A ggplot object depicting the lines of the equations.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
m1 <- matrix(c(1,3, 2, 4), nrow =2)
m2 <- matrix(c(1, 3, 2, 6), nrow =2)
# Consistent system
plot_lines(m = m1, b = c(2, 0))
# Inconsistent system
plot_lines(m = m2, b = c(5, 7))
# Linearly dependent system - only one line appears because there are infinitely many solutions
plot_lines(m = m2, b = c(1, 2))
#Plot many equations at once
m3 <- matrix(sample(-10:10, 10), nrow = 5)
plot_lines(m = m3, b = -2:2)

ryan-heslin/matador documentation built on Dec. 22, 2021, 8:17 p.m.