Math 1003, Week 9, Lecture 17

Lecturer: Eduardo G. Altmann, http://www.maths.usyd.edu.au/u/ega/¶

Models of separable equations

In [1]:
import matplotlib.pyplot as plt
from scipy import *
from scipy import integrate
from scipy.integrate import ode
import numpy as np

%load_ext autoreload
%autoreload 2

%matplotlib inline

Leaking container

$$ \frac{d h}{d t} = -k \sqrt{h}$$

In [22]:
fig = plt.figure(num=1,figsize=(10,10))
ax=fig.add_subplot(111)

xmin=0;xmax=35;ymin=0;ymax=1;
gridx=30;gridy=30;
x=np.array(range(100))/100.;x=xmin+(xmax-xmin)*x;


plt.xlim([xmin,xmax])
plt.ylim([ymin,ymax])
plt.xlabel(r"$t$",fontsize=18)
plt.ylabel(r"$h/H$",fontsize=18)
plt.tick_params(axis='both', which='major', labelsize=16)

k=1

#Vector field
X,Y = np.meshgrid( np.linspace(xmin,xmax,gridx),np.linspace(ymin,ymax,gridy) )
dX = 1
dY = -k*np.sqrt(Y)

#Normalize arrows
N = np.sqrt(dX**2+dY**2)  
U, V = dX/N, dY/N
ax.quiver( X,Y,U, V,minshaft=5,width=0.005,headwidth=0,color="black")


# Ploting solutions derived in classroom
f=(1-(2-np.sqrt(2))*x/20)**2
ax.plot(x,f)

plt.show()

Pollution Problems

$$ \frac{dc}{dt} = \frac{r}{V}(c_1-c) $$

In [28]:
fig = plt.figure(num=1,figsize=(10,10))
ax=fig.add_subplot(111)

xmin=0;xmax=5;ymin=0;ymax=3;
gridx=30;gridy=30;
x=np.array(range(100))/100.;x=xmin+(xmax-xmin)*x;


plt.xlim([xmin,xmax])
plt.ylim([ymin,ymax])
plt.xlabel(r"$t v/r$",fontsize=18)
plt.ylabel(r"$h/H$",fontsize=18)
plt.tick_params(axis='both', which='major', labelsize=16)

c1=1

#Vector field
X,Y = np.meshgrid( np.linspace(xmin,xmax,gridx),np.linspace(ymin,ymax,gridy) )
dX = 1
dY = c1-Y

#Normalize arrows
N = np.sqrt(dX**2+dY**2)  
U, V = dX/N, dY/N
ax.quiver( X,Y,U, V,minshaft=5,width=0.005,headwidth=0,color="black")

c0=2
# Ploting solutions derived in classroom
f=c1+(c0-c1)*exp(-x)
ax.plot(x,f)

c0=0.1*c1
f=c1+(c0-c1)*exp(-x)
ax.plot(x,f)


plt.show()
In []: