Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Is it right answer? Create a graphical output of a mathematical model using arbitrary variables and Python code, but you must use a PID controller.
Is it right answer? Create a graphical output of a mathematical model using arbitrary variables and Python code, but you must use a PID controller.
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
# Constants
R # Gas constant NmkgK
T # Temperature inside the chamber K
V # Volume of the chamber L
k # Adiabatic coefficient
patm # Atmospheric pressure Pa
Sv # Nominal pumping speed of the vacuum pump mh
pv # Ultimate gas pressure of the vacuum pump Pa
Vt # Volume inside the bellows L
# Variables
D # Diameter of valve port
Acu # Effective crosssectional areas of the HSVs for the charging units
Adu # Effective crosssectional areas of the HSVs for the discharging units
alpha # Correction coefficient of the flow area of the valve port
sigma # Critical pressure ratio
d # Duty cycles for the process
# PID Controller Parameters
Kp
Ki
Kd
# Initial conditions
p patm
pt patm
Qm
Qm
Qmv
xvm
# Time points
t nplinspace
epsilon # Small time offset to avoid division by zero at t
# Pressure Differential Equation
def modely t:
p pt Qm Qm Qmv xvm y
fk Qm R T V
fk R T Vt
Qm Qm Qm
fpt SvR T pv pt
tsafe t epsilon # Use tsafe instead of t to avoid division by zero
dpdt f Kp p p Ki p p tsafe Kd p p tsafe
dptdt fQm Qmv
dQmdt Acu patm npsqrtT fp patm dcut
dQmdt Adu p npsqrtT fp pt ddut
dQmvdt f
dxvmdt nppi alpha D xvm p npsqrtT fp pt d
return dpdt dptdt dQmdt dQmdt dQmvdt dxvmdt
# Function fp p
def fp p:
ratio pp sigma
if ratio sigma:
return
else:
adjustedratio max ratio # Ensure the value under the square root is nonnegative
return npsqrtadjustedratio
# Duty cycles
def dcut:
return # Duty cycles for the process of charging
def ddut:
return # Duty cycles for the process of discharging
# Solve ODE
yp pt Qm Qm Qmv xvm
y odeintmodel y t
# Plot results
pltfigurefigsize
pltplott y:r labelp
pltplott y:b labelpt
pltlegendloc'best'
pltxlabelTime s
pltylabelPressure Pa
plttitlePressure Control'
pltgrid
pltshow
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started