Matlab- Thermodynamic filling of tank.

In summary, there are a few potential issues with your code, including using the same temperature throughout, using "P2" as your loop condition, and not accounting for the changing density of the air in the tank. You may need to make some adjustments to your code and equations to get accurate results.
  • #1
Juanka
40
0
Ok, I have an assignment to do in MATLAB involving the following problem, I am having a problem with my results, I believe I have coded everything correctly with the parameters of the problem yet as my plots show, there is an error in my calculations, any suggestions? I am attaching my problem statement and the code I have written.


A 70 ft3 rigid insulated tank contains air at 14.7 psia and 80 º F. The tank is connected to a supply line through a valve. Air is flowing in the supply line at 75 psia and 80 º F. The valve is opened, and air is allowed to enter the tank until the pressure in the tank reaches the line pressure, at which point the valve is closed. The diameter of the connecting pipe is 1 inch.

Write a computer program to model the pressurization process in the tank. The computer program will calculate the pressure, temperature, mass flowrate into the tank and resident mass during the process. Determine the final temperature, mass of air in the tank and time required to pressurize the tank.




Code:
P1=75; % in psi

T1=(80+459.67); %in R

A1=(pi*1)/(4*144); % Area in ft^2

D1=1; % Diameter in inch

P2=(14.7); % in psi

T2=T1; %in R

V2=70; % in ft^3

Cp=0.24; % in Btu/lb-R

Cv=0.17; % in Btu/lb-R

k=1.4;% gamma

Cd=0.6; % is unitless

R=53.33; % in ft-lb/lb/R

rho1=(P1*144)/(R*T1); % density in lb/ft^3

rho2=(P2*144)/(R*T2); % density in lb/ft^3

mass2=(rho2*V2); % mass in lb

g=32.174; % in ft/sec^2

dt=0.01; % change in time intervals

n=1;

m(1)=mass2;

P(1)=P2;

T(1)=T2;


while P2<P1-.01

    error=1;

       n=n+1;

    while error>0.001

        %Equations

       mdot=A1*sqrt(((2*k)/(k-1))*P1*g*rho1*(P2/P1)^(2/k)*(1-(P2/P1))^(k-1/k));

        mass2new=mass2+mdot*dt;

        u=(mass2*Cv*T2+mdot*Cp*T1*dt)/mass2new; %energy equation

        T2=u/Cv;

        P2new=mass2new*R*T2/(V2*144);

        error=abs(P2new-P2)/P2;

        P2=P2new;

    end

    mass2=mass2new;

    T(n)=T2;

    P(n)=P2;

    m(n)=mass2new;

    t(n)=n*dt;

end


%% Output

 
fprintf('The final temperature = %7.3f R\n',T2)

fprintf('The mass of air in tank = %7.3f lb\n',mass2new)

fprintf('The time required to pressurize the tank = %7.3f s\n',t(n))

figure(1)

plot(t,T,'g','Linewidth',2)

grid

ylabel('Temperature (R)')

xlabel('Time (s)')

title('Time Vs Temperature')

figure(2)

plot(t,P,'b','Linewidth',2)

grid

xlabel('Time (s)')

ylabel('Pressure (psi)')

title('Time Vs Pressure')

figure(3)

plot(t,m,'r','Linewidth',2)

grid

xlabel('Time (s)')

ylabel('Mass (lb)')

title('Time Vs Mass')

PLEASE ANY SUGGESTIONS, I cannot seem to get this to run right any ideas will help becuase I cannot think of any other reason why this loop is not working. * My teacher said the answers should be time about 8 seconds and temp around 700 Rankin*
 
Physics news on Phys.org
  • #2


Hi there,

Thank you for sharing your problem and code. From a quick look at your code, it seems like you have all the necessary equations and parameters in place. However, I noticed a few potential issues that could be causing your error.

Firstly, in your while loop, you are using "P2" as your condition for the loop to run. However, you are also updating the value of "P2" within the loop. This could lead to an infinite loop or unexpected results. I would suggest using a different variable for your loop condition, such as "error" or "n".

Secondly, you are using the same value for "T1" and "T2" throughout your code. This means that the temperature of the air entering the tank is always the same as the initial temperature of the air in the tank. In reality, as the air enters the tank, it will be compressed and its temperature will increase. You may need to add a calculation for the temperature of the air entering the tank based on the pressure and density of the air in the supply line.

Lastly, I noticed that your mass flow rate calculation is based on the initial density of the air in the tank, rather than the changing density as the pressure increases. You may need to update your mass flow rate calculation to take into account the changing density of the air in the tank.

I hope these suggestions help you in finding the error in your code. I would also recommend checking your equations and parameters again to make sure they are correct. Best of luck with your assignment!
 

Related to Matlab- Thermodynamic filling of tank.

1. What is thermodynamic filling of a tank in Matlab?

Thermodynamic filling of a tank in Matlab refers to the process of modeling the filling of a tank with a fluid, taking into account the thermodynamic properties of the fluid. It involves solving differential equations that describe the fluid dynamics and thermodynamics of the system.

2. How is the tank filling process modeled using Matlab?

The tank filling process is typically modeled using the mass and energy balance equations, which take into account the inflow and outflow of fluid, as well as the changes in temperature and pressure within the tank. These equations are then solved using numerical methods in Matlab to predict the behavior of the system over time.

3. What are the main benefits of using Matlab for thermodynamic tank filling simulations?

Matlab offers a range of built-in functions and tools for solving complex mathematical and engineering problems, making it an ideal choice for modeling thermodynamic tank filling. It also allows for easy visualization of results and the ability to modify and refine the simulation as needed.

4. How accurate are thermodynamic tank filling simulations in Matlab?

The accuracy of the simulation depends on the accuracy of the input parameters and assumptions used in the model. With proper calibration and validation, Matlab simulations can provide accurate results that closely match real-world observations.

5. Can Matlab be used to simulate different types of fluids in tank filling scenarios?

Yes, Matlab can be used to simulate the filling of tanks with different types of fluids, as long as the appropriate thermodynamic properties and equations are used. Matlab also allows for the incorporation of user-defined functions, making it possible to model a wide range of fluid behavior and properties.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
460
  • Engineering and Comp Sci Homework Help
Replies
14
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top