0% found this document useful (0 votes)
69 views

Math Lab 5 - Jupyter Notebook

This document contains code from a Jupyter Notebook that is working through examples involving symbolic differentiation and solving differential equations symbolically. It imports sympy and defines symbols for variables. It then finds the general solution to a differential equation, computes the derivative of a function, finds the points where that derivative is zero to find maxima and minima, and computes the derivative of a complicated logarithmic function.

Uploaded by

redstonejazz5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Math Lab 5 - Jupyter Notebook

This document contains code from a Jupyter Notebook that is working through examples involving symbolic differentiation and solving differential equations symbolically. It imports sympy and defines symbols for variables. It then finds the general solution to a differential equation, computes the derivative of a function, finds the points where that derivative is zero to find maxima and minima, and computes the derivative of a complicated logarithmic function.

Uploaded by

redstonejazz5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

3/4/24, 7:10 PM math lab 5 - Jupyter Notebook

In [2]: import sympy as sp


from sympy.plotting import (plot,plot_parametric)

In [3]: k, t = sp.symbols('k t')


y = sp.cos(k*t)

diff_eq = sp.diff(y, t, 2) + y
k_solution = sp.solve(diff_eq, k)
print(k_solution)

[-1, 1, pi/(2*t), 3*pi/(2*t)]

In [4]: A, B = sp.symbols('A B')


y_family = A*sp.sin(k*t) + B*sp.cos(k*t)

#substitute values of k solution to family
#check if the values of y satisfy the diff equation

In [5]: #compute dy/dx


x, y = sp.symbols('x y')
lhs = x**2-x*y+y**2
rhs = 3
dydx = sp.idiff(lhs-rhs, y, x)
dydx

Out[5]: 2𝑥 − 𝑦
𝑥 − 2𝑦
In [6]: #make eq1 and eq2, to solve it would be sp.solve then [eq1, eq2], [x,y]
horizontal_p = sp.solve([2*x-y, lhs-rhs],[x,y])
print(horizontal_p)
vertical_p = sp.solve([],[x,y])

[(-1, -2), (1, 2)]

In [7]: pcurve = sp.plot_implicit(lhs - rhs, (x,-2.5,2.5),(y,-2.5,2.5), show=False)

In [20]: #3a
x = sp.symbols('x')
y = (x**4) * ((7+x)**(1-(x**2)))
f = sp.expand_log(sp.log(y), force=True)
print(f)

(1 - x**2)*log(x + 7) + 4*log(x)

In [24]: #3b
logydiff=sp.diff((1-(x**2))*((sp.log(x+7))+4)*(sp.log(x)),x)
print(logydiff)

-2*x*(log(x + 7) + 4)*log(x) + (1 - x**2)*log(x)/(x + 7) + (1 - x**2)*(log(x + 7) + 4)/x

In [25]: #3c
ydiff = logydiff * y
print(ydiff)

x**4*(x + 7)**(1 - x**2)*(-2*x*(log(x + 7) + 4)*log(x) + (1 - x**2)*log(x)/(x + 7) + (1 - x**2)*(log(x + 7) + 4)/x)

In [28]:

ive of the derivative of the log is x**4*(x + 7)**(1 - x**2)*(-2*x*log(x + 7) + (1 - x**2)/(x + 7)) + 4*x**3*(x + 7)**(1 - x**2),

The derivative of y found with the derivative of the derivative of the log is x**4*(x + 7)**(1 - x**2)*(-2*x*log(x + 7) + (1 -
x**2)/(x + 7)) + 4*x**3*(x + 7)**(1 - x**2), the derivative of y is x**4*(x + 7)**(1 - x**2)*(-2*x*log(x + 7) + (1 - x**2)/(x +
7)) + 4*x**3*(x + 7)**(1 - x**2)

In [ ]: ​

localhost:8888/notebooks/math lab 5.ipynb 1/1

You might also like