1/38
Scalar Differential Equations; Systems of Differential Equations
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is a differential equation?
An equation that involves derivatives of one or more dependent variables with respect to one or more independent variables.
What is an Initial Value Problem (IVP)?
A differential equation plus the value of the unknown function at some particular time
What is the general form of an IVP?
x′(t)=f(t,x(t)) x(0)=0
What is the equation for Forward Euler when used on an IVP?
xk+1=xk+Δtf(tk,xk)
Give an example of a Forward Euler Solver.
def forward_euler(ode, IC, t):
"""
t = np.arange(0, T+dt/2, dt)
V = np.zeros(t.size)
Inputs:
- ode = lambda or python function, of the form ode(t,V)
t is independent variable, V is dependent variable
- IC = the initial condition
- t = times at which we want the solution. Extract dt from this.
"""
V = np.zeros(t.size) # Setup solution array
V[0] = IC # Define the initial condition
dt = t[1]-t[0] # Calculate dt
# Use a for loop for Forward Euler
for i in range(t.size - 1):
V[i+1] = V[i] + dt * ode(t[i], V[i])
return VWhat is the equation for Backward Euler when used on an IVP?
xk+1=xk+Δtf(tk+1,xk+1)
What is the format for solve_ivp?
sol = scipy.integrate.solve_ivp(ODE, [start, end], [IC], t_eval = t_span)
What is sol.t ?
The t values at which the approximate solution is found.
What is sol.y[number] ?
The approximate solution at the corresponding t value.
Are “solutions” found numerically approximations to a discretization of the true solution of an IVP?
Yes.
Is the Forward Euler Method explicit or implicit?
explicit
Is the Backward Euler Method explicit or implicit?
implicit
Which is better for solving stiff IVPS? Explicit or implicit methods?
Implicit methods.
What is the order of accuracy of the forward and backward Euler methods?
first-order accurate
What is the FIRST step for using solve_ivp to solve systems of IVPs?
Define both ODEs
What is the SECOND step for using solve_ivp to solve systems of IVPs?
Put the ODEs into an ODE System
What is the THIRD step for using solve_ivp to solve systems of IVPs?
Package them in terms of one dependent-variable input
What is the FINAL step for using solve_ivp to solve systems of IVPs?
Use solve_ivp on the new ODE
Show an example of solve_ivp being used to solve systems of IVPs
dxdt = lambda x, y: 2*x - x*y
dydt = lambda x, y: -0.5*y + 0.2*x*y
ode_system = lambda x, y: np.array([dxdt(x,y), dydt(x,y)])
ode = lambda t, z: ode_system(z[0], z[1])
t_span = np.linspace(0, 15, 1000)
sol = solve_ivp(ode, [0, 15], np.array([6, 2]), t_eval = t_span)How do you plot IVP solutions from systems of ODEs?
ax.plot(t, x)
When does convergence happen?
As x approaches 0.
What is the FIRST step to create phase portraits for 2D systems of IVPs?
Extract time values and z
What is the SECOND step to create phase portraits for 2D systems of IVPs?
Extract x and y from z.
What is the FINAL step to create phase portraits for 2D systems of IVPs?
ax.plot(x, y)
Give an example of a phase portrait for 2D systems of IVPs being created.
dxdt = lambda x, y: 2*x - x*y
dydt = lambda x, y: -0.5*y + 0.2*x*y
ode_system = lambda x, y: np.array([dxdt(x,y), dydt(x,y)])
ode = lambda t, z: ode_system(z[0], z[1])
t_span = np.linspace(0, 15, 1000)
sol = solve_ivp(ode, [0, 15], np.array([6, 2]), t_eval = t_span)
t = sol.t
z = sol.y
x = z[0]
y = z[1]
fig, ax = plt.subplots()
ax.plot(x, y)Give an example of lambda being used.
f = lambda x: x**2 + 4
What is the standard format for def ?
def function_name(parameters):
# Function body
return value # OptionalWhat is the standard format for range?
range(start, stop, step)
Give an example of a Numpy array.
A = np.array([1, 2, 3])
Give an example of a Numpy array filled with zeros.
Z = np.zeros(5)
What is the standard format for Numpy linspace?
np.linspace(start, stop, step)
What does “step” in range and np.arange mean?
The size of increments between numbers.
What does “step” in np.linspace mean?
The number of steps in the array.
What is the standard format for Numpy arange?
np.arange(start, stop, step)
What does np.log() mean?
Natural logarithm
What does np.exp() mean?
e to the x power.
What does scipy.optimize.fsolve do?
It finds the root(s) of a function.
What is the format for scipy.optimize.fsolve ?
root = scipy.optimize.fsolve(function, array)
What are some Matplotlib plot functions?
import matplotlib as plt
fig, ax = plt.subplots()
ax.plot()
plt.show() # or plt.savefig('Name.png')