<jupyter_start><jupyter_text>Solving Linear Systems<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import torch
import tensorflow as tf<jupyter_output><empty_output><jupyter_text>4.1 The Substitution Strategy**Method 1: Substitution**- Use whenever there's a variable in system with coefficient of 1, use the following trick! For the following system:$$ y = 3x $$$$ -5x + 2y = 2 $$Re-arrange the equation of isolate an unknown - $ y$: $$ 2y = 2 + 5x $$$$ y = \frac{2 + 5x}{2} = 1 + \frac{5x}{2} $$<jupyter_code>x = np.linspace(-10, 10, 1000) # starta, finish, n points
y1 = 3 * x
y2 = 1 + (5 * x) /2
fig, ax = plt.subplots(figsize=(8, 5))

plt.title('System of equations', fontsize=20)
plt.xlabel('x', fontsize=15)
plt.ylabel('y', fontsize=15)
ax.set_xlim([0, 3.0])
ax.set_ylim([0, 8])

ax.plot(x, y1, color='green')
ax.plot(x, y2, color='red')
plt.axvline(2.0, color='purple', linestyle='--')
plt.axhline(6, color='purple', linestyle='--')
plt.show()<jupyter_output><empty_output><jupyter_text>4.2 Substitution Exercises 1.  $x + y = 6$  $2x + 3y = 16$   2.  $-x + 4y = 0$  $2x - 5y = -6$    3. $y = 4x + 1$  $-4x + y = 2$    $(x, y) = (2, 4)$  $(x, y) = (-8, -2)$    $No solution!$<jupyter_code>fig, ax = plt.subplots(1, 3, figsize=(18, 5))

y1 = 6 - x
y2 = (16 - (2 * x)) / 3

y3 = x / 4
y4 = ((2 * x) + 6) / 5

y5 = 4*x + 1
y6 = 2 + 4 * x

ax[0].set_title('1 solution', fontsize=15)
ax[0].set_xlim([-5, 10])
ax[0].set_ylim([-5, 15])
ax[0].plot(x, y1, color='red')
ax[0].plot(x, y2, color='green')

ax[1].set_title('1 solution', fontsize=15)
ax[1].set_xlim([-10, 0])
ax[1].set_ylim([-3, 0])
ax[1].plot(x, y3, color='red')
ax[1].plot(x, y4, color='green')

ax[2].set_title('Parallel. No solution', fontsize=15)
ax[2].set_xlim([-10, -5])
ax[2].set_ylim([-30, -20])
ax[2].plot(x, y5, color='red')
ax[2].plot(x, y6, color='green')

plt.show()<jupyter_output><empty_output><jupyter_text>4.3 The Elimination Strategy- Typically best option if no variable in system has coefficient of 1.- Use _addition property_ of equations to eliminate variables.    - If necessary, multiply one or both equations to make elimination of a variable possible.For example, solve for the unknowns in the following system:   $2x - 3y = 15$  $x + 10y = 14$    by multiplying the first equation by -2 and adding the equations.   $(x, y) = (6, -1)$<jupyter_code>x = np.linspace(0, 20, 1000)
y1 = ((2 * x) - 15) / 3
y2 = 14 - x

plt.xlim([5, 20])
plt.ylim([-2, 8])
plt.plot(x, y1, c='red')
plt.plot(x, y2, c='g')
plt.show()<jupyter_output><empty_output><jupyter_text>4.4 Elimination Exercises 1.  $4x - 3y = 25$  $-3x + 8y = 10$   2.  $-9x - 15y = 15$  $3x + 5y = -10$    3. $4x + 2y = 4$  $-5x - 3y = -7$    $(x, y) = (10, 5)$  $No solution!$$(x, y) = (-1, 4)$<jupyter_code>x = np.linspace(-50, 50, 1000)
y1 = (25 - (4 * x)) / -3
y2 = (10 + (3 * x)) / 8

y3 = (15 + (9 * x)) / -15
y4 = (-10 - (3 * x)) / 5

y5 = (4 - 4 * x) / 2
y6 = (-5 * x + 7) / 3

fig, ax = plt.subplots(1, 3, figsize=(18, 5))

ys = [[y1,  y2], [y3, y4], [y5, y6]]

fig.suptitle('Equations and their solutions', fontsize=20)

for i in range(3):
    ax[i].set_xlim([-20, 20])
    ax[i].set_ylim([-20, 20])
    ax[i].plot(x, ys[i][0], c='g')
    ax[i].plot(x, ys[i][1], c='r')

ax[0].set_title('1 solution', fontsize=15)
ax[1].set_title('Parallel. No solution', fontsize=15)
ax[2].set_title('1 solution', fontsize=15)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21650087770626097, 'fraction_numerical': 0.08308952603861908, 'mean_word_length': 3.7420249653259363, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '496205', 'license': 'Apache-2.0', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1531, 'n_words': 405, 'path': '01 Linear Algebra for Machine Learning (Jon Krohn)/04 Solving Linear Systems.ipynb', 'repo_name': 'Coding-Forest/2021-Mathematics', 'size': '3418'}