```python
import numpy as np
import matplotlib.pyplot as plt

from sympy.solvers import solve
from sympy import Symbol

from math import e, log
```

# 4.1 Functions


```python
def f(x):
    return x ** 2

print(f(2))
print(f(-3))
```

    4
    9


## 4.1.4 The Plot of a Function


```python
x = np.linspace(-10, 10, 1000)
x
```




    array([-10.        ,  -9.97997998,  -9.95995996,  -9.93993994,
            -9.91991992,  -9.8998999 ,  -9.87987988,  -9.85985986,
            -9.83983984,  -9.81981982,  -9.7997998 ,  -9.77977978,
            -9.75975976,  -9.73973974,  -9.71971972,  -9.6996997 ,
            -9.67967968,  -9.65965966,  -9.63963964,  -9.61961962,
            -9.5995996 ,  -9.57957958,  -9.55955956,  -9.53953954,
            -9.51951952,  -9.4994995 ,  -9.47947948,  -9.45945946,
            -9.43943944,  -9.41941942,  -9.3993994 ,  -9.37937938,
            -9.35935936,  -9.33933934,  -9.31931932,  -9.2992993 ,
            -9.27927928,  -9.25925926,  -9.23923924,  -9.21921922,
            -9.1991992 ,  -9.17917918,  -9.15915916,  -9.13913914,
            -9.11911912,  -9.0990991 ,  -9.07907908,  -9.05905906,
            -9.03903904,  -9.01901902,  -8.998999  ,  -8.97897898,
            -8.95895896,  -8.93893894,  -8.91891892,  -8.8988989 ,
            -8.87887888,  -8.85885886,  -8.83883884,  -8.81881882,
            -8.7987988 ,  -8.77877878,  -8.75875876,  -8.73873874,
            -8.71871872,  -8.6986987 ,  -8.67867868,  -8.65865866,
            -8.63863864,  -8.61861862,  -8.5985986 ,  -8.57857858,
            -8.55855856,  -8.53853854,  -8.51851852,  -8.4984985 ,
            -8.47847848,  -8.45845846,  -8.43843844,  -8.41841842,
            -8.3983984 ,  -8.37837838,  -8.35835836,  -8.33833834,
            -8.31831832,  -8.2982983 ,  -8.27827828,  -8.25825826,
            -8.23823824,  -8.21821822,  -8.1981982 ,  -8.17817818,
            -8.15815816,  -8.13813814,  -8.11811812,  -8.0980981 ,
            -8.07807808,  -8.05805806,  -8.03803804,  -8.01801802,
            -7.997998  ,  -7.97797798,  -7.95795796,  -7.93793794,
            -7.91791792,  -7.8978979 ,  -7.87787788,  -7.85785786,
            -7.83783784,  -7.81781782,  -7.7977978 ,  -7.77777778,
            -7.75775776,  -7.73773774,  -7.71771772,  -7.6976977 ,
            -7.67767768,  -7.65765766,  -7.63763764,  -7.61761762,
            -7.5975976 ,  -7.57757758,  -7.55755756,  -7.53753754,
            -7.51751752,  -7.4974975 ,  -7.47747748,  -7.45745746,
            -7.43743744,  -7.41741742,  -7.3973974 ,  -7.37737738,
            -7.35735736,  -7.33733734,  -7.31731732,  -7.2972973 ,
            -7.27727728,  -7.25725726,  -7.23723724,  -7.21721722,
            -7.1971972 ,  -7.17717718,  -7.15715716,  -7.13713714,
            -7.11711712,  -7.0970971 ,  -7.07707708,  -7.05705706,
            -7.03703704,  -7.01701702,  -6.996997  ,  -6.97697698,
            -6.95695696,  -6.93693694,  -6.91691692,  -6.8968969 ,
            -6.87687688,  -6.85685686,  -6.83683684,  -6.81681682,
            -6.7967968 ,  -6.77677678,  -6.75675676,  -6.73673674,
            -6.71671672,  -6.6966967 ,  -6.67667668,  -6.65665666,
            -6.63663664,  -6.61661662,  -6.5965966 ,  -6.57657658,
            -6.55655656,  -6.53653654,  -6.51651652,  -6.4964965 ,
            -6.47647648,  -6.45645646,  -6.43643644,  -6.41641642,
            -6.3963964 ,  -6.37637638,  -6.35635636,  -6.33633634,
            -6.31631632,  -6.2962963 ,  -6.27627628,  -6.25625626,
            -6.23623624,  -6.21621622,  -6.1961962 ,  -6.17617618,
            -6.15615616,  -6.13613614,  -6.11611612,  -6.0960961 ,
            -6.07607608,  -6.05605606,  -6.03603604,  -6.01601602,
            -5.995996  ,  -5.97597598,  -5.95595596,  -5.93593594,
            -5.91591592,  -5.8958959 ,  -5.87587588,  -5.85585586,
            -5.83583584,  -5.81581582,  -5.7957958 ,  -5.77577578,
            -5.75575576,  -5.73573574,  -5.71571572,  -5.6956957 ,
            -5.67567568,  -5.65565566,  -5.63563564,  -5.61561562,
            -5.5955956 ,  -5.57557558,  -5.55555556,  -5.53553554,
            -5.51551552,  -5.4954955 ,  -5.47547548,  -5.45545546,
            -5.43543544,  -5.41541542,  -5.3953954 ,  -5.37537538,
            -5.35535536,  -5.33533534,  -5.31531532,  -5.2952953 ,
            -5.27527528,  -5.25525526,  -5.23523524,  -5.21521522,
            -5.1951952 ,  -5.17517518,  -5.15515516,  -5.13513514,
            -5.11511512,  -5.0950951 ,  -5.07507508,  -5.05505506,
            -5.03503504,  -5.01501502,  -4.99499499,  -4.97497497,
            -4.95495495,  -4.93493493,  -4.91491491,  -4.89489489,
            -4.87487487,  -4.85485485,  -4.83483483,  -4.81481481,
            -4.79479479,  -4.77477477,  -4.75475475,  -4.73473473,
            -4.71471471,  -4.69469469,  -4.67467467,  -4.65465465,
            -4.63463463,  -4.61461461,  -4.59459459,  -4.57457457,
            -4.55455455,  -4.53453453,  -4.51451451,  -4.49449449,
            -4.47447447,  -4.45445445,  -4.43443443,  -4.41441441,
            -4.39439439,  -4.37437437,  -4.35435435,  -4.33433433,
            -4.31431431,  -4.29429429,  -4.27427427,  -4.25425425,
            -4.23423423,  -4.21421421,  -4.19419419,  -4.17417417,
            -4.15415415,  -4.13413413,  -4.11411411,  -4.09409409,
            -4.07407407,  -4.05405405,  -4.03403403,  -4.01401401,
            -3.99399399,  -3.97397397,  -3.95395395,  -3.93393393,
            -3.91391391,  -3.89389389,  -3.87387387,  -3.85385385,
            -3.83383383,  -3.81381381,  -3.79379379,  -3.77377377,
            -3.75375375,  -3.73373373,  -3.71371371,  -3.69369369,
            -3.67367367,  -3.65365365,  -3.63363363,  -3.61361361,
            -3.59359359,  -3.57357357,  -3.55355355,  -3.53353353,
            -3.51351351,  -3.49349349,  -3.47347347,  -3.45345345,
            -3.43343343,  -3.41341341,  -3.39339339,  -3.37337337,
            -3.35335335,  -3.33333333,  -3.31331331,  -3.29329329,
            -3.27327327,  -3.25325325,  -3.23323323,  -3.21321321,
            -3.19319319,  -3.17317317,  -3.15315315,  -3.13313313,
            -3.11311311,  -3.09309309,  -3.07307307,  -3.05305305,
            -3.03303303,  -3.01301301,  -2.99299299,  -2.97297297,
            -2.95295295,  -2.93293293,  -2.91291291,  -2.89289289,
            -2.87287287,  -2.85285285,  -2.83283283,  -2.81281281,
            -2.79279279,  -2.77277277,  -2.75275275,  -2.73273273,
            -2.71271271,  -2.69269269,  -2.67267267,  -2.65265265,
            -2.63263263,  -2.61261261,  -2.59259259,  -2.57257257,
            -2.55255255,  -2.53253253,  -2.51251251,  -2.49249249,
            -2.47247247,  -2.45245245,  -2.43243243,  -2.41241241,
            -2.39239239,  -2.37237237,  -2.35235235,  -2.33233233,
            -2.31231231,  -2.29229229,  -2.27227227,  -2.25225225,
            -2.23223223,  -2.21221221,  -2.19219219,  -2.17217217,
            -2.15215215,  -2.13213213,  -2.11211211,  -2.09209209,
            -2.07207207,  -2.05205205,  -2.03203203,  -2.01201201,
            -1.99199199,  -1.97197197,  -1.95195195,  -1.93193193,
            -1.91191191,  -1.89189189,  -1.87187187,  -1.85185185,
            -1.83183183,  -1.81181181,  -1.79179179,  -1.77177177,
            -1.75175175,  -1.73173173,  -1.71171171,  -1.69169169,
            -1.67167167,  -1.65165165,  -1.63163163,  -1.61161161,
            -1.59159159,  -1.57157157,  -1.55155155,  -1.53153153,
            -1.51151151,  -1.49149149,  -1.47147147,  -1.45145145,
            -1.43143143,  -1.41141141,  -1.39139139,  -1.37137137,
            -1.35135135,  -1.33133133,  -1.31131131,  -1.29129129,
            -1.27127127,  -1.25125125,  -1.23123123,  -1.21121121,
            -1.19119119,  -1.17117117,  -1.15115115,  -1.13113113,
            -1.11111111,  -1.09109109,  -1.07107107,  -1.05105105,
            -1.03103103,  -1.01101101,  -0.99099099,  -0.97097097,
            -0.95095095,  -0.93093093,  -0.91091091,  -0.89089089,
            -0.87087087,  -0.85085085,  -0.83083083,  -0.81081081,
            -0.79079079,  -0.77077077,  -0.75075075,  -0.73073073,
            -0.71071071,  -0.69069069,  -0.67067067,  -0.65065065,
            -0.63063063,  -0.61061061,  -0.59059059,  -0.57057057,
            -0.55055055,  -0.53053053,  -0.51051051,  -0.49049049,
            -0.47047047,  -0.45045045,  -0.43043043,  -0.41041041,
            -0.39039039,  -0.37037037,  -0.35035035,  -0.33033033,
            -0.31031031,  -0.29029029,  -0.27027027,  -0.25025025,
            -0.23023023,  -0.21021021,  -0.19019019,  -0.17017017,
            -0.15015015,  -0.13013013,  -0.11011011,  -0.09009009,
            -0.07007007,  -0.05005005,  -0.03003003,  -0.01001001,
             0.01001001,   0.03003003,   0.05005005,   0.07007007,
             0.09009009,   0.11011011,   0.13013013,   0.15015015,
             0.17017017,   0.19019019,   0.21021021,   0.23023023,
             0.25025025,   0.27027027,   0.29029029,   0.31031031,
             0.33033033,   0.35035035,   0.37037037,   0.39039039,
             0.41041041,   0.43043043,   0.45045045,   0.47047047,
             0.49049049,   0.51051051,   0.53053053,   0.55055055,
             0.57057057,   0.59059059,   0.61061061,   0.63063063,
             0.65065065,   0.67067067,   0.69069069,   0.71071071,
             0.73073073,   0.75075075,   0.77077077,   0.79079079,
             0.81081081,   0.83083083,   0.85085085,   0.87087087,
             0.89089089,   0.91091091,   0.93093093,   0.95095095,
             0.97097097,   0.99099099,   1.01101101,   1.03103103,
             1.05105105,   1.07107107,   1.09109109,   1.11111111,
             1.13113113,   1.15115115,   1.17117117,   1.19119119,
             1.21121121,   1.23123123,   1.25125125,   1.27127127,
             1.29129129,   1.31131131,   1.33133133,   1.35135135,
             1.37137137,   1.39139139,   1.41141141,   1.43143143,
             1.45145145,   1.47147147,   1.49149149,   1.51151151,
             1.53153153,   1.55155155,   1.57157157,   1.59159159,
             1.61161161,   1.63163163,   1.65165165,   1.67167167,
             1.69169169,   1.71171171,   1.73173173,   1.75175175,
             1.77177177,   1.79179179,   1.81181181,   1.83183183,
             1.85185185,   1.87187187,   1.89189189,   1.91191191,
             1.93193193,   1.95195195,   1.97197197,   1.99199199,
             2.01201201,   2.03203203,   2.05205205,   2.07207207,
             2.09209209,   2.11211211,   2.13213213,   2.15215215,
             2.17217217,   2.19219219,   2.21221221,   2.23223223,
             2.25225225,   2.27227227,   2.29229229,   2.31231231,
             2.33233233,   2.35235235,   2.37237237,   2.39239239,
             2.41241241,   2.43243243,   2.45245245,   2.47247247,
             2.49249249,   2.51251251,   2.53253253,   2.55255255,
             2.57257257,   2.59259259,   2.61261261,   2.63263263,
             2.65265265,   2.67267267,   2.69269269,   2.71271271,
             2.73273273,   2.75275275,   2.77277277,   2.79279279,
             2.81281281,   2.83283283,   2.85285285,   2.87287287,
             2.89289289,   2.91291291,   2.93293293,   2.95295295,
             2.97297297,   2.99299299,   3.01301301,   3.03303303,
             3.05305305,   3.07307307,   3.09309309,   3.11311311,
             3.13313313,   3.15315315,   3.17317317,   3.19319319,
             3.21321321,   3.23323323,   3.25325325,   3.27327327,
             3.29329329,   3.31331331,   3.33333333,   3.35335335,
             3.37337337,   3.39339339,   3.41341341,   3.43343343,
             3.45345345,   3.47347347,   3.49349349,   3.51351351,
             3.53353353,   3.55355355,   3.57357357,   3.59359359,
             3.61361361,   3.63363363,   3.65365365,   3.67367367,
             3.69369369,   3.71371371,   3.73373373,   3.75375375,
             3.77377377,   3.79379379,   3.81381381,   3.83383383,
             3.85385385,   3.87387387,   3.89389389,   3.91391391,
             3.93393393,   3.95395395,   3.97397397,   3.99399399,
             4.01401401,   4.03403403,   4.05405405,   4.07407407,
             4.09409409,   4.11411411,   4.13413413,   4.15415415,
             4.17417417,   4.19419419,   4.21421421,   4.23423423,
             4.25425425,   4.27427427,   4.29429429,   4.31431431,
             4.33433433,   4.35435435,   4.37437437,   4.39439439,
             4.41441441,   4.43443443,   4.45445445,   4.47447447,
             4.49449449,   4.51451451,   4.53453453,   4.55455455,
             4.57457457,   4.59459459,   4.61461461,   4.63463463,
             4.65465465,   4.67467467,   4.69469469,   4.71471471,
             4.73473473,   4.75475475,   4.77477477,   4.79479479,
             4.81481481,   4.83483483,   4.85485485,   4.87487487,
             4.89489489,   4.91491491,   4.93493493,   4.95495495,
             4.97497497,   4.99499499,   5.01501502,   5.03503504,
             5.05505506,   5.07507508,   5.0950951 ,   5.11511512,
             5.13513514,   5.15515516,   5.17517518,   5.1951952 ,
             5.21521522,   5.23523524,   5.25525526,   5.27527528,
             5.2952953 ,   5.31531532,   5.33533534,   5.35535536,
             5.37537538,   5.3953954 ,   5.41541542,   5.43543544,
             5.45545546,   5.47547548,   5.4954955 ,   5.51551552,
             5.53553554,   5.55555556,   5.57557558,   5.5955956 ,
             5.61561562,   5.63563564,   5.65565566,   5.67567568,
             5.6956957 ,   5.71571572,   5.73573574,   5.75575576,
             5.77577578,   5.7957958 ,   5.81581582,   5.83583584,
             5.85585586,   5.87587588,   5.8958959 ,   5.91591592,
             5.93593594,   5.95595596,   5.97597598,   5.995996  ,
             6.01601602,   6.03603604,   6.05605606,   6.07607608,
             6.0960961 ,   6.11611612,   6.13613614,   6.15615616,
             6.17617618,   6.1961962 ,   6.21621622,   6.23623624,
             6.25625626,   6.27627628,   6.2962963 ,   6.31631632,
             6.33633634,   6.35635636,   6.37637638,   6.3963964 ,
             6.41641642,   6.43643644,   6.45645646,   6.47647648,
             6.4964965 ,   6.51651652,   6.53653654,   6.55655656,
             6.57657658,   6.5965966 ,   6.61661662,   6.63663664,
             6.65665666,   6.67667668,   6.6966967 ,   6.71671672,
             6.73673674,   6.75675676,   6.77677678,   6.7967968 ,
             6.81681682,   6.83683684,   6.85685686,   6.87687688,
             6.8968969 ,   6.91691692,   6.93693694,   6.95695696,
             6.97697698,   6.996997  ,   7.01701702,   7.03703704,
             7.05705706,   7.07707708,   7.0970971 ,   7.11711712,
             7.13713714,   7.15715716,   7.17717718,   7.1971972 ,
             7.21721722,   7.23723724,   7.25725726,   7.27727728,
             7.2972973 ,   7.31731732,   7.33733734,   7.35735736,
             7.37737738,   7.3973974 ,   7.41741742,   7.43743744,
             7.45745746,   7.47747748,   7.4974975 ,   7.51751752,
             7.53753754,   7.55755756,   7.57757758,   7.5975976 ,
             7.61761762,   7.63763764,   7.65765766,   7.67767768,
             7.6976977 ,   7.71771772,   7.73773774,   7.75775776,
             7.77777778,   7.7977978 ,   7.81781782,   7.83783784,
             7.85785786,   7.87787788,   7.8978979 ,   7.91791792,
             7.93793794,   7.95795796,   7.97797798,   7.997998  ,
             8.01801802,   8.03803804,   8.05805806,   8.07807808,
             8.0980981 ,   8.11811812,   8.13813814,   8.15815816,
             8.17817818,   8.1981982 ,   8.21821822,   8.23823824,
             8.25825826,   8.27827828,   8.2982983 ,   8.31831832,
             8.33833834,   8.35835836,   8.37837838,   8.3983984 ,
             8.41841842,   8.43843844,   8.45845846,   8.47847848,
             8.4984985 ,   8.51851852,   8.53853854,   8.55855856,
             8.57857858,   8.5985986 ,   8.61861862,   8.63863864,
             8.65865866,   8.67867868,   8.6986987 ,   8.71871872,
             8.73873874,   8.75875876,   8.77877878,   8.7987988 ,
             8.81881882,   8.83883884,   8.85885886,   8.87887888,
             8.8988989 ,   8.91891892,   8.93893894,   8.95895896,
             8.97897898,   8.998999  ,   9.01901902,   9.03903904,
             9.05905906,   9.07907908,   9.0990991 ,   9.11911912,
             9.13913914,   9.15915916,   9.17917918,   9.1991992 ,
             9.21921922,   9.23923924,   9.25925926,   9.27927928,
             9.2992993 ,   9.31931932,   9.33933934,   9.35935936,
             9.37937938,   9.3993994 ,   9.41941942,   9.43943944,
             9.45945946,   9.47947948,   9.4994995 ,   9.51951952,
             9.53953954,   9.55955956,   9.57957958,   9.5995996 ,
             9.61961962,   9.63963964,   9.65965966,   9.67967968,
             9.6996997 ,   9.71971972,   9.73973974,   9.75975976,
             9.77977978,   9.7997998 ,   9.81981982,   9.83983984,
             9.85985986,   9.87987988,   9.8998999 ,   9.91991992,
             9.93993994,   9.95995996,   9.97997998,  10.        ])




```python
plt.plot(x, x + 1)
plt.show()
```

# 4.3 Equations

## 4.3.3 Using Python


```python
x = Symbol('x')
x
```




$\displaystyle x$




```python
solve(x ** 3 - 7 * x ** 2 + 15 * x - 9, x)
```




    [1, 3]




```python
solve(3 * e ** (x + 2) + 3 - 2 * (e ** x + 100), x)
```




    [2.27914777845756]




```python
log(197 / (3 * e ** 2 - 2))
```




    2.279147778457572



# 4.4 Systems of Equations

# 4.4.2 Systems of Non-Linear Equations


```python
x = Symbol('x')
y = Symbol('y')

solve(
    [x + y - 5, x ** 2 - x + 2 * y - 8],
    x, y
)
```




    [(1, 4), (2, 3)]




```python
solve(
    [x ** 2 - 2 * x - y ** 2 + 1, x ** 2 - 2 * y - 1],
    x, y
)
```




    [(-3, 4), (1, 0)]




```python

```

a8860bf42994e8da4ff174f406c9d208d8b49274
ipynb
Jupyter Notebook
Code Samples.ipynb
Develop-Packt/Using-Functions-and-Algebra-with-Python
5f5b4c37e40216cb5751687f5bb9d6378652ab14
MIT
Code Samples.ipynb
Develop-Packt/Using-Functions-and-Algebra-with-Python
5f5b4c37e40216cb5751687f5bb9d6378652ab14
MIT
Code Samples.ipynb
Develop-Packt/Using-Functions-and-Algebra-with-Python
5f5b4c37e40216cb5751687f5bb9d6378652ab14
MIT
2021-02-25T16:24:53.000Z
2021-02-25T16:24:53.000Z
Qwen/Qwen-72B
1. YES
2. YES