初识代数方程一

解方程

简单的一元一次方程

x + 16 = − 25 x + 16 − 16 = − 25 − 16 x = − 25 − 16 x = − 41 \begin{array}{l}x+16=-25 \\ x+16-16=-25-16 \\ x=-25-16 \\ x=-41\end{array} x+16=25x+1616=2516x=2516x=41

x = -41                # 验证方程的解
x + 16 == -25
True

带系数的方程

3 x − 2 = 10 3 x − 2 + 2 = 10 + 2 3 x = 12 x = 4 \begin{array}{l}3 x-2=10 \\ 3 x-2+2=10+2 \\ 3 x=12 \\ x=4\end{array} 3x2=103x2+2=10+23x=12x=4

x = 4                  # 代入 x = 4
3 * x - 2 == 10
True

系数是分数的方程

x 3 + 1 = 16 x 3 = 15 3 1 ⋅ x 3 = 15 ⋅ 3 x = 45 \begin{array}{l}\frac{x}{3}+1=16 \\ \frac{x}{3}=15 \\ \frac{3}{1} \cdot \frac{x}{3}=15 \cdot 3 \\ x=45\end{array} 3x+1=163x=15133x=153x=45

x = 45
x/3 + 1 == 16
True

需要合并同类项的例子

3 x + 2 = 5 x − 1 3 x + 3 = 5 x 3 = 2 x 3 2 = x x = 3 2 x = 1 1 2 \begin{array}{l}3 x+2=5 x-1 \\ 3 x+3=5 x \\ 3=2 x \\ \frac{3}{2}=x \\ x=\frac{3}{2} \\ x=1 \frac{1}{2}\end{array} 3x+2=5x13x+3=5x3=2x23=xx=23x=121

x = 1.5
3*x + 2 == 5*x -1
True

一元方程练习

4 ( x + 2 ) + 3 ( x − 2 ) = 16 4 x + 8 + 3 x − 6 = 16 7 x + 2 = 16 7 x = 14 7 x 7 = 14 7 x = 2 \begin{array}{l}4(x+2)+3(x-2)=16 \\ 4 x+8+3 x-6=16 \\ 7 x+2=16 \\ 7 x=14 \\ \frac{7 x}{7}=\frac{14}{7} \\ x=2\end{array} 4(x+2)+3(x2)=164x+8+3x6=167x+2=167x=1477x=714x=2

x = 2
4 * (x + 2) + 3 * (x - 2) == 16
True

线性方程

例子

2 y + 3 = 3 x − 1 2 y + 4 = 3 x 2 y = 3 x − 4 y = 3 x − 4 2 \begin{array}{l}2 y+3=3 x-1 \\ 2 y+4=3 x \\ 2 y=3 x-4 \\ y=\frac{3 x-4}{2}\end{array} 2y+3=3x12y+4=3x2y=3x4y=23x4

import numpy as np
from tabulate import tabulate

x = np.array(range(-10, 11))  # 从 -10 到 10 的21个数据点
y = (3 * x - 4) / 2           # 对应的函数值

print(tabulate(np.column_stack((x,y)), headers=['x', 'y']))
  x      y
---  -----
-10  -17
 -9  -15.5
 -8  -14
 -7  -12.5
 -6  -11
 -5   -9.5
 -4   -8
 -3   -6.5
 -2   -5
 -1   -3.5
  0   -2
  1   -0.5
  2    1
  3    2.5
  4    4
  5    5.5
  6    7
  7    8.5
  8   10
  9   11.5
 10   13
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "last_expr"
# %matplotlib inline
from matplotlib import pyplot as plt

plt.plot(x, y, color="grey", marker = "o")
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SfXUtcwM-1609746991704)(output_13_0.png)]

截距

plt.plot(x, y, color="grey")
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.axhline()                # 画出坐标轴
plt.axvline()
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8jXbqMiS-1609746991705)(output_15_0.png)]

  • x轴上的截距

0 = 3 x − 4 2 3 x − 4 2 = 0 3 x − 4 = 0 3 x = 4 x = 4 3 x = 1 1 3 \begin{array}{l}0=\frac{3 x-4}{2} \\ \frac{3 x-4}{2}=0 \\ 3 x-4=0 \\ 3 x=4 \\ x=\frac{4}{3} \\ x=1 \frac{1}{3}\end{array} 0=23x423x4=03x4=03x=4x=34x=131

  • y轴上的截距

y = 3 ⋅ 0 − 4 2 y = − 4 2 y = − 2 \begin{array}{l}y=\frac{3 \cdot 0-4}{2} \\ y=\frac{-4}{2} \\ y=-2\end{array} y=2304y=24y=2

plt.plot(x, y, color="grey")
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.axhline()
plt.axvline()
plt.annotate('x',(1.333, 0)) # 标出截距点
plt.annotate('y',(0,-2))
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GXOaeJrQ-1609746991706)(output_17_0.png)]

截距的作用是明显的:两点成一线。连接截距就可以画出函数曲线。

斜率

slope  = Δ y Δ x m = y 2 − y 1 x 2 − x 1 m = 7 − − 2 6 − 0 m = 7 + 2 6 − 0 m = 1.5 \begin{array}{l}\text {slope }=\frac{\Delta y}{\Delta x} \\ m=\frac{y_{2}-y_{1}}{x_{2}-x_{1}} \\ m=\frac{7--2}{6-0} \\ m=\frac{7+2}{6-0} \\ m=1.5\end{array} slope =ΔxΔym=x2x1y2y1m=6072m=607+2m=1.5

plt.plot(x, y, color="grey")
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.axhline()
plt.axvline()
m = 1.5
xInt = 4 / 3
yInt = -2
mx = [0, xInt]
my = [yInt, yInt + m * xInt]
plt.plot(mx, my, color='red', lw=5)  # 用红色标出
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RiGsDfI7-1609746991707)(output_20_0.png)]

plt.grid()                             # 放大图
plt.axhline()
plt.axvline()
m = 1.5
xInt = 4 / 3
yInt = -2
mx = [0, xInt]
my = [yInt, yInt + m * xInt]
plt.plot(mx, my, color='red', lw=5) 
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QO5795N9-1609746991708)(output_21_0.png)]

直线的斜率、截距形式

y = m x + b y = 3 x − 4 2 y = 1 1 2 x + − 2 \begin{array}{l}y=m x+b \\ y=\frac{3 x-4}{2} \\ y=1 \frac{1}{2} x+-2\end{array} y=mx+by=23x4y=121x+2

m = 1.5
yInt = -2

x = np.array(range(-10, 11))
y2 = m * x + yInt                       # 斜率截距形式

plt.plot(x, y2, color="grey")
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.axhline()
plt.axvline()

plt.annotate('y', (0, yInt))
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GhrM3znT-1609746991710)(output_23_0.png)]

线形方程组

解的含义:直线的交点

\begin{equation}x + y = 16 \end{equation}
\begin{equation}10x + 25y = 250 \end{equation}

l1p1 = [16, 0]  # 线1点1
l1p2 = [0, 16]  # 线1点2


l2p1 = [25,0]   # 线2点1
l2p2 = [0,10]   # 线2点2


plt.plot(l1p1,l1p2, color='blue')
plt.plot(l2p1, l2p2, color="orange")
plt.xlabel('x')
plt.ylabel('y')
plt.grid()

plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zyyfpOPU-1609746991711)(output_25_0.png)]

解线形方程组 (消去法)

x + y = 16 10 x + 25 y = 250 − 10 ( x + y ) = − 10 ( 16 ) 10 x + 25 y = 250 − 10 x + − 10 y = − 160 10 x + 25 y = 250 15 y = 90 y = 90 15 y = 6 x + 6 = 16 x = 10 \begin{array}{l}x+y=16 \\ 10 x+25 y=250 \\ -10(x+y)=-10(16) \\ 10 x+25 y=250 \\ -10 x+-10 y=-160 \\ 10 x+25 y=250 \\ 15 y=90 \\ y=\frac{90}{15} \\ y=6 \\ x+6=16 \\ x=10\end{array} x+y=1610x+25y=25010(x+y)=10(16)10x+25y=25010x+10y=16010x+25y=25015y=90y=1590y=6x+6=16x=10

x = 10
y = 6
print ((x + y == 16) & ((10 * x) + (25 * y) == 250))
True

指数、根和对数

指数

2 2 = 2 ⋅ 2 = 4 2 3 = 2 ⋅ 2 ⋅ 2 = 8 \begin{array}{l}2^{2}=2 \cdot 2=4 \\ 2^{3}=2 \cdot 2 \cdot 2=8\end{array} 22=22=423=222=8

x = 5**3
print(x)
125

? 2 = 9 9 = 3 64 3 = 4 \begin{array}{l}?^{2}=9 \\ \sqrt{9}=3 \\ \sqrt[3]{64}=4\end{array} ?2=99 =3364 =4

import math

x = math.sqrt(9)            # 平方根
print (x)

cr = round(64 ** (1. / 3))   # 立方根
print(cr)
3.0
4

根是分数形式的指数

8 1 3 = 8 3 = 2 9 1 2 = 9 = 3 \begin{array}{l}8^{\frac{1}{3}}=\sqrt[3]{8}=2 \\ 9^{\frac{1}{2}}=\sqrt{9}=3\end{array} 831=38 =2921=9 =3

print (9**0.5)
print (math.sqrt(9))
3.0
3.0

对数

对数是指数的逆运算

4 ? = 16 log ⁡ 4 ( 16 ) = 2 \begin{array}{l}4^{?}=16 \\ \log _{4}(16)=2\end{array} 4?=16log4(16)=2

x = math.log(16, 4)
print(x)
2.0

以10为底的对数

log ⁡ ( 64 ) = 1.8061 \log (64)=1.8061 log(64)=1.8061

自然对数

log ⁡ e ( 64 ) = ln ⁡ ( 64 ) = 4.1589 \log _{e}(64)=\ln (64)=4.1589 loge(64)=ln(64)=4.1589

print(math.log10(64))

print (math.log(64))
1.806179973983887
4.1588830833596715

幂运算 (合并同类项)

2 y = 2 x 4 ( x 2 + 2 x 2 x 3 ) 2 y = 2 x 4 ( 3 x 2 x 3 ) 2 y = 2 x 4 ( 3 x − 1 ) 2 y = 6 x 3 y = 3 x 3 \begin{array}{l}2 y=2 x^{4}\left(\frac{x^{2}+2 x^{2}}{x^{3}}\right) \\ 2 y=2 x^{4}\left(\frac{3 x^{2}}{x^{3}}\right) \\ 2 y=2 x^{4}\left(3 x^{-1}\right) \\ 2 y=6 x^{3} \\ y=3 x^{3}\end{array} 2y=2x4(x3x2+2x2)2y=2x4(x33x2)2y=2x4(3x1)2y=6x3y=3x3

x = np.array(range(-10, 11))
y3 = 3 * x ** 3

print(tabulate(np.column_stack((x, y3)), headers=['x', 'y']))
  x      y
---  -----
-10  -3000
 -9  -2187
 -8  -1536
 -7  -1029
 -6   -648
 -5   -375
 -4   -192
 -3    -81
 -2    -24
 -1     -3
  0      0
  1      3
  2     24
  3     81
  4    192
  5    375
  6    648
  7   1029
  8   1536
  9   2187
 10   3000
plt.plot(x, y3, color="magenta")  # y3是曲线
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.axhline()
plt.axvline()
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-weu8HHRc-1609746991712)(output_41_0.png)]

看一个成指数增长的例子

y = 2 x y=2^{x} y=2x

y4 = 2.0**x
plt.plot(x, y4, color="magenta")
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.axhline()
plt.axvline()
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YM6uMwDm-1609746991714)(output_43_0.png)]

复利计算

存款100,年利5%,20年后余额是多少(记复利)

y 1 = 100 + ( 100 ⋅ 0.05 ) y 1 = 100 ⋅ 1.05 y 2 = 100 ⋅ 1.05 ⋅ 1.05 y 2 = 100 ⋅ 1.0 5 2 y 20 = 100 ⋅ 1.0 5 20 \begin{array}{l}y 1=100+(100 \cdot 0.05) \\ y 1=100 \cdot 1.05 \\ y 2=100 \cdot 1.05 \cdot 1.05 \\ y 2=100 \cdot 1.05^{2} \\ y 20=100 \cdot 1.05^{20}\end{array} y1=100+(1000.05)y1=1001.05y2=1001.051.05y2=1001.052y20=1001.0520

year = np.array(range(1, 21))                      # 年份
balance = 100 * (1.05 ** year)                     # 余额
plt.plot(year, balance, color="green")
plt.xlabel('Year')
plt.ylabel('Balance')
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4i2w50x5-1609746991715)(output_45_0.png)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值