Answered step by step
Verified Expert Solution
Link Copied!

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 =287.1 # N(m)/(k)gK
T =293 # K
V =0.8 # L
k =1.4
p_atm =101.325 # kPa
S_v =15.1 # (m^3)/(h)
p_v =0.7 # Pa
V_t =1.3 # L
# Variables
D =1 # Arbitrary diameter
A_cu =1 # Arbitrary area
A_du =1 # Arbitrary area
alpha =1 # Correction coefficient of the flow area of the valve port
sigma =0.5 # Critical pressure ratio
d =1
# PID Controller Parameters
Kp =0.1
Ki =0.01
Kd =0.01
# Initial conditions
p0= p_atm
p_t0= p_atm
Q_m1=0
Q_m2=0
Q_mv =0
x_vm =0
# Time points
t = np.linspace(0,100,1000)
# Pressure Differential Equation
def model(y, t):
p, p_t, Q_m1, Q_m2, Q_mv, x_vm = y
f1=(k * Q_m1* R * T)/ V
f2=(k * R * T)/ V_t
Q_m = Q_m1- Q_m2
f3=(p_t * S_v)/(R * T)*(1- p_v / p_t)
dpdt = f1- Kp *(p - p0)- Ki *(p - p0)* t - Kd *(p - p0)/ t
dp_tdt = f2*(Q_m2- Q_mv)
dQ_m1dt =0.0404* A_cu * p_atm / np.sqrt(T)* f(p, p_atm)* d_cu(t)
dQ_m2dt =0.0404* A_du * p / np.sqrt(T)* f(p, p_t)* d_du(t)
dQ_mvdt = f3
dx_vm_dt =0.0404* np.pi * alpha * D * x_vm * p / np.sqrt(T)* f(p, p_t)* d
return [dpdt, dp_tdt, dQ_m1dt, dQ_m2dt, dQ_mvdt, dx_vm_dt]
# Function f(p1, p2)
def f(p_1, p_2):
if p_2/(p_1*(1- sigma))= sigma:
return 1
else:
return np.sqrt(1-(p_2/(1- sigma))**2)
# Duty cycles
def d_cu(t):
return 0.5 # Duty cycles for the process of charging
def d_du(t):
return 0.5 # Duty cycles for the process of discharging
# Solve ODE
y0=[p0, p_t0, Q_m1, Q_m2, Q_mv, x_vm]
y = odeint(model, y0, t)
# Plot results
plt.figure()
plt.plot(t, y[:,0],'r', label='p(t)')
plt.plot(t, y[:,1],'b', label='p_t(t)')
plt.legend(loc='best')
plt.xlabel('time')
plt.ylabel('pressure')
plt.title('Pressure Control with PID Controller')
plt.grid()
plt.show()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Who should be involved?

Answered: 1 week ago