All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective: To solve a given set of Ordinary Differential equations using the Multi-Variate Newton Raphson Method. Given: The set of ODE's are given below: dy1dt=-0.04⋅y1+104⋅y2⋅y3dy1dt=−0.04⋅y1+104⋅y2⋅y3 dy2dt=0.04⋅y1-104⋅y2⋅y3-3⋅107⋅y22dy2dt=0.04⋅y1−104⋅y2⋅y3−3⋅107⋅y22 dy3dt=3⋅107⋅y22dy3dt=3⋅107⋅y22 The jacobian should be estimated numerically and not analytically.…
GAURAV KHARWADE
updated on 01 Nov 2020
Objective: To solve a given set of Ordinary Differential equations using the Multi-Variate Newton Raphson Method.
Given: The set of ODE's are given below:
dy1dt=-0.04⋅y1+104⋅y2⋅y3dy1dt=−0.04⋅y1+104⋅y2⋅y3
dy2dt=0.04⋅y1-104⋅y2⋅y3-3⋅107⋅y22dy2dt=0.04⋅y1−104⋅y2⋅y3−3⋅107⋅y22
dy3dt=3â‹…107â‹…y22dy3dt=3â‹…107â‹…y22
The jacobian should be estimated numerically and not analytically. The initial conditions are 1 for y1 and 0 for y2 and y3 respectively.
Take alpha as 1. Run the simulation for 10 minutes.
Theory:
Multi-Variate Newton Raphson MethodMulti-Variate Newton Raphson Method
As we know, the Multivariate Newton-Raphson method is a direct extension of the single variable Newton-Raphson method. Where the single variable Newton-Raphson method solved
f(x)=0f(x)=0, the multivariate version will solve a system of n equations of the form:
f1(x1,x2,x3.....,xn-1,xn)=0f1(x1,x2,x3.....,xn−1,xn)=0
f2(x1,x2,x3.....,xn-1,xn)=0f2(x1,x2,x3.....,xn−1,xn)=0
f3(x1,x2,x3.....,xn-1,xn)=0f3(x1,x2,x3.....,xn−1,xn)=0
.
.
.
.
fn-1(x1,x2,x3.....,xn-1,xn)=0fn−1(x1,x2,x3.....,xn−1,xn)=0
fn(x1,x2,x3.....,xn-1,xn)=0fn(x1,x2,x3.....,xn−1,xn)=0
We will adopt the shorthand notation for the equation.
f(x)=0f(x)=0
According to Multi-variate Newton Raphson Method, to get the solution out of coupled non-linear ODE below equation we use:
ynew=yold-α⋅J-1⋅Fynew=yold−α⋅J−1⋅F
where, alpha - Relaxation factor
Vector F will be written as,
f=[f1f2f3..fn]
Old value or Guess value will be written as,
yold=[y1 oldy2 oldy3 old..yn old]
Jacobian Matrix,
J=[df1dy1df1dy2df1dy3df2dy1df2dy2df2dy3df3dy1df3dy2df2dy3..]
where, nos. of column= Nos. of independent variables
nos. of Rows= Nos. of Functions
Solution:
Python Code:
"""
Program to solve non-linear coupled ODE with multi-variate Newton Raphson Solver
System of coupled non-linear ODE is:
-0.04 * Y1 + 10^4 * Y2*Y3 = 0
0.04 * Y1 - 10^4 *Y2*Y3 - 3 * 10^7* Y2^2 = 0
3 * 10^7* Y2^2 = 0
By- Gaurav V Kharwade || Skill-Lync:2020
"""
import numpy.matlib
import numpy as np
import numpy.linalg
import matplotlib.pyplot as plt
def f1(y1,y2,y3,y1_old,dt): # First non-linear equation
return (y1_old + dt*(-0.04*y1 + 1e4*y2*y3) - y1)
def f2(y1,y2,y3,y2_old,dt): # Second non-linear equation
return (y2_old + dt*(0.04*y1 - (1e4*y2*y3) - (3*1e7*y2*y2)) - y2)
def f3(y1,y2,y3,y3_old,dt): # Third non-linear equation
return (y3_old + dt*(3e7*y2*y2) - y3)
def jacobian(y1,y2,y3,y1_old,y2_old,y3_old,dt): # To define Jacobian matrix
#To define 3 * 3 matrix creation
j= np.ones((3,3))
# Step-size
h = 1e-6
"""
For estimation of jacobian matrix we have used numerical method(BDS) instead analytical method
"""
# Row 1
j[0,0]= (f1(y1+h,y2,y3,y1_old,dt)-f1(y1,y2,y3,y1_old,dt))/h
j[0,1]= (f1(y1,y2+h,y3,y1_old,dt)-f1(y1,y2,y3,y1_old,dt))/h
j[0,2]= (f1(y1,y2,y3+h,y1_old,dt)-f1(y1,y2,y3,y1_old,dt))/h
# Row 2
j[1,0]= (f2(y1+h,y2,y3,y2_old,dt)-f2(y1,y2,y3,y2_old,dt))/h
j[1,1]= (f2(y1,y2+h,y3,y2_old,dt)-f2(y1,y2,y3,y2_old,dt))/h
j[1,2]= (f2(y1,y2,y3+h,y2_old,dt)-f2(y1,y2,y3,y2_old,dt))/h
# Row 3
j[2,0]= (f3(y1+h,y2,y3,y3_old,dt)-f3(y1,y2,y3,y3_old,dt))/h
j[2,1]= (f3(y1,y2+h,y3,y3_old,dt)-f3(y1,y2,y3,y3_old,dt))/h
j[2,2]= (f3(y1,y2,y3+h,y3_old,dt)-f3(y1,y2,y3,y3_old,dt))/h
return j
# Initialisation
y1_old= 1
y2_old= 0
y3_old= 0
# Old value assignment
y_old= np.ones((3,1))
y_old[0]= y1_old
y_old[1]= y2_old
y_old[2]= y3_old
# Column vector of function F
F= np.copy(y_old)
# Relaxation factor
alpha= 1
# Total time, T=10 mins, t= 10 * 60
t= 600
# Time step
dt= 0.1
n= int(t/dt)
# Array of updated values
y_new1= []
y_new2= []
y_new3= []
it= []
error_updated= []
# Initialising iteration
iter= 1
# For loop, to time stepping
for i in range(0,n):
# Newton Raphson criteria
tol= 9e-6
error= 9e9
# Newton Raphson Solver
while error > tol:
# Jacobi Matrix
j= jacobian(y_old[0],y_old[1],y_old[2],y1_old,y2_old,y3_old,dt)
# F column vector
F[0]= f1(y_old[0],y_old[1],y_old[2],y1_old,dt);
F[1]= f2(y_old[0],y_old[1],y_old[2],y2_old,dt);
F[2]= f3(y_old[0],y_old[1],y_old[2],y3_old,dt);
# Equation for solver
y_new = y_old - alpha * np.matmul(numpy.linalg.inv(j), F);
# Error finding
error = np.max(np.abs(y_new - y_old));
print(error)
# Old value updation
y_old = y_new
# To print on console
log= 'iter= {0} error= {1} y1= {2} y2= {3} y3= {4} '.format(iter,error, y_new[0], y_new[1], y_new[2])
print(log)
y_old = y_new;
y_new1.append(y_new[0])
y_new2.append(y_new[1])
y_new3.append(y_new[2])
error_updated.append(error)
iter= iter + 1
it.append(iter)
# Old value updation
y1_old= y_new[0]
y2_old= y_new[1]
y3_old= y_new[2]
# To create a plot of error dropping
plt.plot(it,error_updated,'--',color='red')
plt.yscale("log")
plt.title('Error dropping characteristics')
plt.xlabel('Iteration nos.')
plt.ylabel('Error value')
plt.grid('on')
# To create a figure with 3 rowa and 1 column of subplot
fig, ax= plt.subplots(3)
# For convergence of y1
ax[0].plot(it,y_new1)
ax[0].set_title('Convergence of y1')
ax[0].grid('on')
# For convergence of y1
ax[1].semilogy(it,y_new2)
ax[1].set_title('Convergence of y2')
ax[1].grid('on')
# For convergence of y3
ax[2].plot(it,y_new3)
ax[2].set_title('Convergence of y3')
ax[2].grid('on')
fig.tight_layout()
plt.show()
Results:
After running the program the results we get is as below:
We can see above the error values that we have targeted have achieved and the solution for this ODE has shown above.
y1= 0.39997579, y2= 2.63177e-6 & y3= 0.600021
We can see below, at each and every iterations we are getting closer to an accurate value.
In this plot, we can see how the errors are getting dropped at every iteration in order to achieve a solution with high accuracy.
I ran the program by using a time step much lower than 0.1, but it has been observed that there was no major variation in the solution obtained. Hence, choosing 0.1 as time step will be a better choice as it helps us to get solutions in less time and with high accuracy also.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 9 - Senstivity Analysis Assignment
Objective: To write the code which will take entire reactions of GRI mechanism 3.0 and take out the most sensitive top 10 reactions. The main parameters are as follows: Write code to list out the top 10 most sensitive reactions from a list of all reactions from the GRI mechanism. The sensitivity parameters should be with…
04 Jan 2021 05:51 PM IST
Auto ignition analysis of combustible mixture methane under different conditions using Cantera and Python
Objective: To study auto-ignition using Cantera. Following are the tasks to perform using Cantera: Plot the variation of Auto Ignition time of Methane with a constant temperature of 1250K and pressure varying from 1 to 5 atm. Plot the variation of Auto Ignition time…
06 Dec 2020 04:55 AM IST
Week 6 - Multivariate Newton Rhapson Solver
Objective: To solve a given set of Ordinary Differential equations using the Multi-Variate Newton Raphson Method. Given: The set of ODE's are given below: dy1dt=-0.04⋅y1+104⋅y2⋅y3 dy2dt=0.04⋅y1-104⋅y2⋅y3-3⋅107⋅y22 dy3dt=3⋅107⋅y22 The jacobian should be estimated numerically and not analytically.…
01 Nov 2020 03:50 AM IST
Week 5 - Literature review: ODE Stability
Objective: To review the literature about ODE and to write the python program to substantiate our results. Theory: …
20 Oct 2020 03:52 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.