Could someone please help me with my code I have spent a lot of time working on it and I still didn4t figure out what is the problem
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
R=8.314/32;
T0=2930;
a=(12)/((2.027*10^6)^0.45);
rhoP=1920;
Astar=pi*0.25^2;
k=1.35;
n=0.45;
P0=101325;
%syms P(t)
%at beginning of the integration set initial values for the persistent variables
rp=0.35; %initial port radius
v0=pi*rp^2*8;
t1=0; %initial time step
dP=@(t,P)Fun(t,P,R,T0,rp,a,n,Ab,P0,rhoP,Astar,k,v0);%@(t,P)(Ab.*a.*P.^n.*(rhoP-rhoO)-P.*Astar.*sqrt(k/(R.*T0)).*(2/(k+1)).^((k+1)/(2.*(k-1)))).*R.*T0./v0;
[t,P]=ode45(dP, [0,0.001], P0);
figure(1)
plot(t,y)
xlabel("Time (s)")
ylabel("Chamber Pressure (Pa)")
title("Chamber Pressure vs Time (Start-Up)")
dP=@(t1,P)Fun(t,P,R,T0,rp,a,n,t1,Ab,P0,rhoP,Astar,k,v0);%@(t,P)(Ab.*a.*P.^n.*(rhoP-rhoO)-P.*Astar.*sqrt(k/(R.*T0)).*(2/(k+1)).^((k+1)/(2.*(k-1)))).*R.*T0./v0;
[t,P]=ode45(dP, [0,60], P0);
hold on
figure(2)
plot(t,y)
xlabel("Time (s)")
ylabel("Chamber Pressure (Pa)")
title("Chamber Pressure vs Time ")
hold off
function dP = Fun(t,P,Ab,R,T0,rp,a,n,rhoP,Astar,k)
dP=0;
if t==0
rp=0.35;
end
Ab=2*pi*rp*8;
rhoO=P/(R*T0);
rp>=0.7
Ab=0;
v0=pi*rp^2*8;
t1=t;
rp=min(rp+((a*P^n)*10^-3)*(t-t1),0.7);
Ab=2*pi*rp*8;
dP = (Ab.*a.*P.^n.*(rhoP-rhoO)-P.*Astar.*sqrt(k/(R.*T0)).*(2/(k+1)).^((k+1)/(2.*(k-1)))).*R.*T0./v0;
end
3 comentarios
Stephen23
el 3 de Nov. de 2019
Editada: Stephen23
el 3 de Nov. de 2019
The function input arguments are inconsistent:
Fun(t,P,R,T0,rp,a,n,Ab,P0,rhoP,Astar,k,v0) % function call
Fun(t,P,Ab,R,T0,rp,a,n,rhoP,Astar,k) % function definition
Aligned on the matching names:
Fun(t,P, R,T0,rp,a,n,Ab,P0,rhoP,Astar,k,v0) % function call
Fun(t,P,Ab,R,T0,rp,a,n, rhoP,Astar,k ) % function definition
Respuestas (1)
Subhadeep Koley
el 6 de Nov. de 2019
As rightly pointed by Stephen Cobeldick, the function input arguments are inconsistent. I have made some changes in the script and the function. Check whether it is providing your expected output or not.
SCRIPT
clear;close all;clc;
R=8.314/32;
T0=2930;
a=(12)/((2.027*10^6)^0.45);
rhoP=1920;
Astar=pi*0.25^2;
k=1.35;
n=0.45;
P0=101325;
%syms P(t)
%at beginning of the integration set initial values for the persistent variables
rp=0.35; %initial port radius
v0=pi*rp^2*8;
t1=0; %initial time step
dP=@(t,P)Fun(t,P,R,T0,rp,a,n,rhoP,Astar,k);%@(t,P)(Ab.*a.*P.^n.*(rhoP-rhoO)-P.*Astar.*sqrt(k/(R.*T0)).*(2/(k+1)).^((k+1)/(2.*(k-1)))).*R.*T0./v0;
[t,P]=ode45(dP, [0,0.001], P0);
figure(1);
plot(t,P);
xlabel("Time (s)");
ylabel("Chamber Pressure (Pa)");
title("Chamber Pressure vs Time (Start-Up)");
dP=@(t,P)Fun(t,P,R,T0,rp,a,n,rhoP,Astar,k);%@(t,P)(Ab.*a.*P.^n.*(rhoP-rhoO)-P.*Astar.*sqrt(k/(R.*T0)).*(2/(k+1)).^((k+1)/(2.*(k-1)))).*R.*T0./v0;
[t,P]=ode45(dP, [0,60], P0);
hold on;
figure(2);
plot(t,P);
xlabel("Time (s)");
ylabel("Chamber Pressure (Pa)");
title("Chamber Pressure vs Time ");
hold off;
FUNCTION
function dP = Fun(t,P,R,T0,rp,a,n,rhoP,Astar,k)
if t==0
rp=0.35;
end
rhoO=P/(R*T0);
rp>=0.7;
v0=pi*rp^2*8;
t1=t;
rp=min(rp+((a*P^n)*10^-3)*(t-t1),0.7);
Ab=2*pi*rp*8;
dP = (Ab.*a.*P.^n.*(rhoP-rhoO)-P.*Astar.*sqrt(k/(R.*T0)).*(2/(k+1)).^((k+1)/(2.*(k-1)))).*R.*T0./v0;
end
Hope this helps!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!