Why is this error popping up for this script?

1 view (last 30 days)
Nick Olibrice
Nick Olibrice on 21 Jul 2022
Commented: KSSV on 21 Jul 2022
P1 = 101 %pressure in kpa
P1 = 101
T1 = 298%temperature in kelvin
T1 = 298
n = 1.4
n = 1.4000
Cp = 1.004
Cp = 1.0040
Cv = 0.717
Cv = 0.7170
R = 0.287 %gas constant in kJ/kg*k
R = 0.2870
v1 = R * T1/P1 %specific volume in m^3/kg
v1 = 0.8468
IsentConst1 = P1 * v1^n
IsentConst1 = 80.0219
P2 = 28 * 101 %outlet compressor/inlet combuster pressure
P2 = 2828
v2 = (P1 *v1^n / 2)^(1-n)
v2 = 0.2286
T2 = P2 * v2 / R
T2 = 2.2528e+03
Wc = Cp * (T2 - T1)
Wc = 1.9626e+03
P3 = P2
P3 = 2828
T3 = 2260
T3 = 2260
v3 = R * T3 / P3
v3 = 0.2294
IsentConst2 = P3 * v3^n
IsentConst2 = 359.9107
T4 = (Wc / Cp) + T3
T4 = 4.2148e+03
v4 = ((P3 * v3^n)/(R * T4)^(1/n-1))
v4 = 2.7350e+03
P4 = R * T4 /v4
P4 = 0.4423
IsentConst3 = P4 * v4^n
IsentConst3 = 2.8671e+04
u4 = Cv * T4
u4 = 3.0220e+03
h4 = u4 + P4 * v4
h4 = 4.2317e+03
P5 = P1
P5 = 101
v5 = (P4 *v4^n / P5)^(1/n)
v5 = 56.5236
T5 = P5 *v5 / R
T5 = 1.9892e+04
u5 = Cv * T5
u5 = 1.4262e+04
h5 = u5 + P5 * v5
h5 = 1.9971e+04
dh = (h4 - h5)*1000 %performance parameter
dh = -1.5739e+07
i = 0;
for v = v1:-0.001:v2
i = i + 1;
v = v1:0.001:v2
P(i) = IsentConst1 \ v.^n;
end
v = 1×0 empty double row vector
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
v = v1:-0.001:v2;
plot(v,P,'r','lineWidth',1.5)

Answers (1)

KSSV
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:
  1. Think is your code correct. I don't think so. Use logic.
  2. DEbug the code.
  3. Read about the problem.
  4. Take basic course in MATLAB.
  2 Comments
Nick Olibrice
Nick Olibrice on 21 Jul 2022
how could i plot P-v diagram, error says there is no function of P
KSSV
KSSV on 21 Jul 2022
clc; clear all ;
P1 = 101 %pressure in kpa
P1 = 101
T1 = 298%temperature in kelvin
T1 = 298
n = 1.4
n = 1.4000
Cp = 1.004
Cp = 1.0040
Cv = 0.717
Cv = 0.7170
R = 0.287 %gas constant in kJ/kg*k
R = 0.2870
v1 = R * T1/P1 %specific volume in m^3/kg
v1 = 0.8468
IsentConst1 = P1 * v1^n
IsentConst1 = 80.0219
P2 = 28 * 101 %outlet compressor/inlet combuster pressure
P2 = 2828
v2 = (P1 *v1^n / 2)^(1-n)
v2 = 0.2286
T2 = P2 * v2 / R
T2 = 2.2528e+03
Wc = Cp * (T2 - T1)
Wc = 1.9626e+03
P3 = P2
P3 = 2828
T3 = 2260
T3 = 2260
v3 = R * T3 / P3
v3 = 0.2294
IsentConst2 = P3 * v3^n
IsentConst2 = 359.9107
T4 = (Wc / Cp) + T3
T4 = 4.2148e+03
v4 = ((P3 * v3^n)/(R * T4)^(1/n-1))
v4 = 2.7350e+03
P4 = R * T4 /v4
P4 = 0.4423
IsentConst3 = P4 * v4^n
IsentConst3 = 2.8671e+04
u4 = Cv * T4
u4 = 3.0220e+03
h4 = u4 + P4 * v4
h4 = 4.2317e+03
P5 = P1
P5 = 101
v5 = (P4 *v4^n / P5)^(1/n)
v5 = 56.5236
T5 = P5 *v5 / R
T5 = 1.9892e+04
u5 = Cv * T5
u5 = 1.4262e+04
h5 = u5 + P5 * v5
h5 = 1.9971e+04
dh = (h5 - h4)*1000 %performance parameter
dh = 1.5739e+07
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)

Sign in to comment.

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!