- Think is your code correct. I don't think so. Use logic.
- DEbug the code.
- Read about the problem.
- Take basic course in MATLAB.
Why is this error popping up for this script?
1 view (last 30 days)
Show older comments
P1 = 101 %pressure in kpa
T1 = 298%temperature in kelvin
n = 1.4
Cp = 1.004
Cv = 0.717
R = 0.287 %gas constant in kJ/kg*k
v1 = R * T1/P1 %specific volume in m^3/kg
IsentConst1 = P1 * v1^n
P2 = 28 * 101 %outlet compressor/inlet combuster pressure
v2 = (P1 *v1^n / 2)^(1-n)
T2 = P2 * v2 / R
Wc = Cp * (T2 - T1)
P3 = P2
T3 = 2260
v3 = R * T3 / P3
IsentConst2 = P3 * v3^n
T4 = (Wc / Cp) + T3
v4 = ((P3 * v3^n)/(R * T4)^(1/n-1))
P4 = R * T4 /v4
IsentConst3 = P4 * v4^n
u4 = Cv * T4
h4 = u4 + P4 * v4
P5 = P1
v5 = (P4 *v4^n / P5)^(1/n)
T5 = P5 *v5 / R
u5 = Cv * T5
h5 = u5 + P5 * v5
dh = (h4 - h5)*1000 %performance parameter
i = 0;
for v = v1:-0.001:v2
i = i + 1;
v = v1:0.001:v2
P(i) = IsentConst1 \ v.^n;
end
v = v1:-0.001:v2;
plot(v,P,'r','lineWidth',1.5)
0 Comments
Answers (1)
KSSV
on 21 Jul 2022
In the loop:
i = 0;
for v = v1:-0.001:v2
i = i + 1;
v = v1:0.001:v2 %<---- this is empty matrix.
P(i) = IsentConst1 \ v.^n; %<---- as v is empty, result is empty matrix and you cannot save
end
Work around:
v = v1:-0.001:v2 ;
Then this line:
IsentConst1 \ v.^n
will be an array and you cannot save it into a single element.
You have to use:
P{i} = IsentConst1 \ v.^n;
Prior to this:
2 Comments
KSSV
on 21 Jul 2022
clc; clear all ;
P1 = 101 %pressure in kpa
T1 = 298%temperature in kelvin
n = 1.4
Cp = 1.004
Cv = 0.717
R = 0.287 %gas constant in kJ/kg*k
v1 = R * T1/P1 %specific volume in m^3/kg
IsentConst1 = P1 * v1^n
P2 = 28 * 101 %outlet compressor/inlet combuster pressure
v2 = (P1 *v1^n / 2)^(1-n)
T2 = P2 * v2 / R
Wc = Cp * (T2 - T1)
P3 = P2
T3 = 2260
v3 = R * T3 / P3
IsentConst2 = P3 * v3^n
T4 = (Wc / Cp) + T3
v4 = ((P3 * v3^n)/(R * T4)^(1/n-1))
P4 = R * T4 /v4
IsentConst3 = P4 * v4^n
u4 = Cv * T4
h4 = u4 + P4 * v4
P5 = P1
v5 = (P4 *v4^n / P5)^(1/n)
T5 = P5 *v5 / R
u5 = Cv * T5
h5 = u5 + P5 * v5
dh = (h5 - h4)*1000 %performance parameter
i = 0;
for v = v1:-0.001:v2
i = i + 1;
P(i) = IsentConst1 \ v.^n; %<---- as v is empty, result is empty matrix and you cannot save
end
v = v1:-0.001:v2;
plot(v,P,'r','lineWidth',1.5)
See Also
Categories
Find more on Combustion and Turbomachinery in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!