```python
## This cell just imports necessary modules
%pylab notebook
from sympy import sin, cos, Function, Symbol, diff, integrate, exp
```


```python
###### FIRST PARTIAL DERIVATIVES ######
###### Lecture 2, slide 10 ######

# Define the independent variables using Symbol
r = Symbol('r')
h = Symbol('h')
# Define the function V(r,h)
V = pi*(r**2)*h

# The first partial derivative of V w.r.t h (i.e. r is kept constant)
print("The first partial derivative of V w.r.t. h is: ", diff(V, h))
# The first partial derivative of V w.r.t r (i.e. h is kept constant)
print("The first partial derivative of V w.r.t. r is: ", diff(V, r))

```


```python
###### SECOND PARTIAL DERIVATIVES ######
###### Lecture 2, slide 12 ######

x = Symbol('x')
y = Symbol('y')
f = (x**2)*sin(y)

f_x = diff(f, x)
f_y = diff(f, y)

print("The first partial derivatives of f = (x**2)*sin(y) are: ")
print("f_x = ", f_x)
print("f_y = ", f_y, "\n")

f_xx = diff(f_x, x)
f_xy = diff(f_x, y)
f_yx = diff(f_y, x)
f_yy = diff(f_y, y)

print("The second partial derivatives of f = (x**2)*sin(y) are: ")
print("f_xx = ", f_xx)
print("f_xy = ", f_xy)
print("f_yy = ", f_yy)
print("f_yx = ", f_yx)
```


```python
###### CHAIN RULE ######
###### Lecture 2, slide 19 ######
a = Symbol('a')
b = Symbol('b')
t = Symbol('t')

x = a*t
y = b*t

T = 3*y*sin(x)

# SymPy automatically applies the chain rule here:
print("Differentiating T = 3*y*sin(x) wrt t using the chain rule: \n")
print(diff(T, t))
```


```python
###### DEFINITE AND INDEFINITE INTEGRALS ######
###### Lecture 2, slide 21 ######
x = Symbol('x')
y = Symbol('y')

# Remember: Indefinite integrals result in a constant 'c'. SymPy sets this to zero.
# f is the function we want to integrate.
f = cos(x)

# The second argument is the variable we want to integrate with respect to.
# (in this example, it is 'x').
print("Integrating cos(x) yields:")
print(integrate(f, x)) 

# Using integrate(2*x, (x, a, b)) evaluates a DEFINITE integral between x=a and x=b
a = 0
b = 2
print("Integrating 2*x between x=0 and x=2 yields:")
print(integrate(2*x, (x, a, b)))
```


```python
###### DOUBLE INTEGRALS ######
###### Lecture 2, slide 26 ######

# The function we want to integrate.
f = 2*(x**2)*y

# First integrate f wrt y between y=0 and y=2.
inner_integral = integrate(f, (y, 0, 2)) 
print("The inner integral is: ", inner_integral)

# Then integrate the inner_integral wrt x.
outer_integral = integrate(inner_integral, (x, 0, 2)) 
print("The outer integral is: ", outer_integral)
```

8c6fdec406b0144d0ebb5d963843068ee88717de
ipynb
Jupyter Notebook
mathematics/mm1/Lecture_2_Multivariable_Calculus.ipynb
jrper/thebe-test
554484b1422204a23fe47da41c6dc596a681340f
MIT
mathematics/mm1/Lecture_2_Multivariable_Calculus.ipynb
jrper/thebe-test
554484b1422204a23fe47da41c6dc596a681340f
MIT
mathematics/mm1/Lecture_2_Multivariable_Calculus.ipynb
jrper/thebe-test
554484b1422204a23fe47da41c6dc596a681340f
MIT
Qwen/Qwen-72B
1. YES
2. YES