Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please check my Python code and edit it . Q . Create a graphical output of a mathematical model using arbitrary variables and Python code,
Please check my Python code and edit it Q 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 # NmkgK T # K V # L k patm # kPa Sv # mh pv # Pa Vt # L # Variables D # Arbitrary diameter Acu # Arbitrary area Adu # Arbitrary area alpha # Correction coefficient of the flow area of the valve port sigma # Critical pressure ratio d # PID Controller Parameters Kp Ki Kd # Initial conditions p patm pt patm Qm Qm Qmv xvm # Time points t nplinspace # 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 dpdt f Kp p p Ki p p t Kd p p t 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: if pp sigma sigma: return else: return npsqrtp sigma # 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 pltfigure pltplott y:r labelpt pltplott y:b labelptt pltlegendloc'best' pltxlabeltime pltylabelpressure plttitlePressure Control with PID Controller' pltgrid pltshow
Please check my Python code and edit it
Q 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 # NmkgK
T # K
V # L
k
patm # kPa
Sv # mh
pv # Pa
Vt # L
# Variables
D # Arbitrary diameter
Acu # Arbitrary area
Adu # Arbitrary area
alpha # Correction coefficient of the flow area of the valve port
sigma # Critical pressure ratio
d
# PID Controller Parameters
Kp
Ki
Kd
# Initial conditions
p patm
pt patm
Qm
Qm
Qmv
xvm
# Time points
t nplinspace
# 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
dpdt f Kp p p Ki p p t Kd p p t
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:
if pp sigma sigma:
return
else:
return npsqrtp sigma
# 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
pltfigure
pltplott y:r labelpt
pltplott y:b labelptt
pltlegendloc'best'
pltxlabeltime
pltylabelpressure
plttitlePressure Control with PID Controller'
pltgrid
pltshow
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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