Thesis and Viva
It’s been quite a year for me! I got a new job almost a year ago, wrote up my thesis, moved to a new city and I am about to move house again. Oh, and I just ...
Differential equations are central to the study of the natural world. They describe everything from the flow of fluids through pipes to the evolution of electrons in boxes. These equations naturally get very complicated very quickly thus we must put down our sharp pencils and turn to the more bluntened approach (albeit vastly more powerful) of numerical methods.
In this series I will explore how to solve Differential equations using computers and the fascinating methods which have been developed to solve the most complicated of these devils. We shall explore methods such as Parallel computing and Machine Learning , examine different approaches such as Density Matrix Renormalization Group and investigate how these approaches compare to one another.
We begin these posts with some simple ways to solve Ordinary Differential Equations (ODE’s). We could solve these problems analytically however whilst some ODE’s can be solved this way most cannot. Most differential equations that are useful to us are not solvable analytically, in fact we are not sure that a solution even exists at all points (Navier Stokes etc). However we are saved (as always) by the existence of computers. We can numerically solve these equations to find an approximate answer. The most basic version of this is the first order finite difference method or Euler method, using this method we can solve first order initial Value problems which take the form
The equation we would like to solve is
from math import e # The exponential function for the solution
import numpy as np # Numpy for manipulation of arrays
import matplotlib.pyplot as plt # For plotting the result
Next we define all of the variables and constants we need and implement the inital conditions
h = 1.0 # large step size at first
Y = []
Y.append(1)
Y_true = []
Y_true.append(e**0) # Initial Condition
t_lst = []
t_lst.append(0)# Initial Condition
Now we implement the algorithm
for i in range(0,5):
Y.append(Y[i] + h*Y[i]) # Forward Euler method
t_lst.append((i+1)*h)
for i in range(50):
#Using Smaller step size for the true solution to approximate the continuum
Y_true.append(e**((i+1)*0.1))
t_lstT.append((i+1)*0.1)
from math import sin, cos
import numpy as np
import matplotlib.pyplot as plt
h1 = 0.3
Y1 = [];U1 = [];t_lst1 = []
#Initial Conditions
Y1.append(1)
U1.append(1)
t_lst1.append(0)
for i in range(0,100):
U1.append(U1[i] - Y1[i]*h1)
Y1.append(Y1[i] + U1[i]*h1)
t_lst1.append(h1*i)
plt.plot(t_lst1,Y1,label='h=0.3')
plt.xlim((0,20))
plt.ylim((-20,20))
plt.legend()
plt.xlabel("Time")
plt.ylabel("y(t)")
plt.title("Euler Method for Second Order ODE's")
plt.show()
Which produces the result
As can be easily seen the Euler method breaks down for this oscillating solution but why is this? Can we predict if this is going to occur? Are there any improvements we can make to stop this from happening or at least reduce the error.
All of these and more will be answered in my next posts.
It’s been quite a year for me! I got a new job almost a year ago, wrote up my thesis, moved to a new city and I am about to move house again. Oh, and I just ...
First Quantum Computing Hackathon
A Bog Standard Introdution to Quantum Computing As with most introductions to scientific books and blogs there always has to be sections that are repeated ev...
Now that we have dealt with the ordinary differential equations we can go one of two ways. We can explore how to solve all types of these ODE’s and keep on s...
Quantum Computing is posed to become one of the most useful technologies invented. It boasts algorithms that can outperform some of the best classical algori...
Previously we discussed how to solve some simple ODE’s and looked at coding a simple forward Euler algorithm. However we found that the solution we used does...
Differential equations are central to the study of the natural world. They describe everything from the flow of fluids through pipes to the evolution of elec...