How can I write a loop with for?

2 Ansichten (letzte 30 Tage)
Rana Önem
Rana Önem am 27 Mai 2020
Kommentiert: Rana Önem am 28 Mai 2020
There is a homework, I do interpolations and some calculations and I need to do this 10 times. But some numbers have to change. I am confused. I have to use for to a loop but HOW? Can you help me?
  2 Kommentare
David Hill
David Hill am 27 Mai 2020
Show us what you have done and ask a specific question.
Rana Önem
Rana Önem am 27 Mai 2020
A 3-m3 insulated tank contains water as saturated vapor at 6000 kPa. A valve on top is opened, and only saturated vapor escapes.
During the process, any liquid formed collects at the bottom; so only saturated vapor exits. We want to find the mass that has escaped
when the final pressure drops to 1000 kPa. We know that using an average enthalpy for the saturated vapor exiting leads to an
approximate solution.
First solve the problem analytically using the average exit enthalpy between 6000 and 1000 kPa. Then, solve it by a computer program
you write, dividing the process into TEN steps with piecewise average values of the exit enthalpy. Use 6000-5500 kPa, 5500-5000
kPa, 5000-4500 kPa and so on, down to 1000 kPa as the steps in which the problem is solved. The ten-step solution will result in a
better estimate.
This is what I wrote:
table=importdata('Saturatedpressure_table.txt');
saturatedWater=table.data;
Pressure=saturatedWater(:,1);
Temperature=saturatedWater(:,2);
specificVolume_f=saturatedWater(:,3);
specificVolume_fg=saturatedWater(:,4);
specificVolume_g=saturatedWater(:,5);
internalEnergy_f=saturatedWater(:,6);
internalEnergy_fg=saturatedWater(:,7);
internalEnergy_g=saturatedWater(:,8);
enthalpy_f=saturatedWater(:,9);
enthalpy_fg=saturatedWater(:,10);
enthalpy_g=saturatedWater(:,11);
P2=5500; %kPa;
value2=ismember(P2,Pressure);
if value2==1
fprintf ('No need to make interpolation\n')
else
fprintf('Make interpolation\n')
end
A=find(Pressure<P2);
j=A(end);
B=find(Pressure>P2);
k=B(1);
P3=Pressure(j);
P4=Pressure(k);
vf1=specificVolume_f(j);
vf2=specificVolume_f(k);
vfg1=specificVolume_fg(j);
vfg2=specificVolume_fg(k);
vg1=specificVolume_g(j);
vg2=specificVolume_g(k);
uf1=internalEnergy_f(j);
uf2=internalEnergy_f(k);
ufg1=internalEnergy_fg(j);
ufg2=internalEnergy_fg(k);
ug1=internalEnergy_g(j);
ug2=internalEnergy_g(k);
hg1=enthalpy_g(j);
hg2=enthalpy_g(k);
x=1; %quality all vapor;
vg=vg1+ (vg2-vg1)* (P2-P3)/(P4-P3); %vg value at P=5550 kPa;
hg=hg1+ (hg2-hg1)* (P2-P3)/(P4-P3); %hg value at P=5500 kPa;
ug=ug1+ (ug2-ug1)* (P2-P3)/(P4-P3); %ug value at P=5500 kPa;
P1=6000; %kPa;
value1=ismember(P1,Pressure);
if value1==1
fprintf ('No need to make interpolation\n')
else
fprintf('Make interpolation\n');
end
i=find(Pressure==P1);
P=Pressure(i);
vg3= specificVolume_g(i); %vg value at P=6000 kPa;
hg3=enthalpy_g(i); %hg value at P=6000 kPa;
ug3=internalEnergy_g(i); %ug value at P=6000 kPa;
v=3; %m^3;
m1=v/vg3;
m2=v/vg;
he= (hg3+hg)/2;
m2*(he-ug)== m1*(he-ug3);
m=m1-m2; %m is the escape mass

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 28 Mai 2020
I suggest going through Chapter 13 of MATLAB Onramp. Lesson 3 introduces for loops.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by