Help With Integrating a function with certain bounds

2 Ansichten (letzte 30 Tage)
Areg Arzoomanian
Areg Arzoomanian am 14 Mär. 2020
Kommentiert: Walter Roberson am 14 Mär. 2020
So here is my code:
%% Givens
P1= 160; %kpa
P2= 500; %kpa
P3= P2; %kpa
Mg= 2; %kg
Mf= 1; %kg
Mt= 3; %kg
syms V1 V2
V3=1.2*V1; %m^3
V3=1.2*V1==V2; %m^3
%% Part A
%Table A-5 %
Pa=160;
Pl= 150; Ph= 175; P2= 500;
vfl= 0.001053; vfh= 0.001057; vf2= 0.001093;
vgl= 1.1594; vgh= 1.0037; vg2= 0.37483;
Tl= 111.35; Th= 116.04; T_500= 151.83;
%Table A-6
P2= 500;
Tl2= 600; Th2=700;
vl2= 0.80409; vh2= 0.89696;
% To test if state '2' is in vapor or staurated
Vfa= ((vfh-vfl)/(Ph-Pl))*(Pa-Pl)+vfl;
Vga= ((vgh-vgl)/(Ph-Pl))*(Pa-Pl)+vgl;
X=Mg/Mt;
v1=Vfa+X*(Vga-Vfa);
V1=v1*Mt;
V3=1.2*V1;
V2=V1;
v2=V1/Mt;
v3=V3/Mt;
if X<1;
T1= ((Th-Tl)/(Ph-Pl))*(Pa-Pl)+Tl
end
if v2>vg2
T2= ((Th2-Tl2)/(vh2-vl2))*(v3-vl2)+Tl2
else T2=T_500
end
%% Part B
if v2>vg2
Mf=0
end
%% Part C
for P=P1;
V_1=V1; V_2=V2;
fun= @(V) P.*V;
Work_12= integral(fun,V_1,V_2)
end
for P=P2;
V_2=V2; V_3=V3;
fun=@(V) P*V;
Work_23= integral(fun,V_2,V_3)
end
Work_total=Work_12+Work_23
Everything works, except the final part "Part C"
For Work_23, I need to take the integral of 'P dV' with the bounds being V2 and V3. Basically once integrated I need it to look like P2(V3-V2) and im expecting an answer of 219.xxx however its giving me 530.xxx. Can someone please help

Antworten (1)

Walter Roberson
Walter Roberson am 14 Mär. 2020
fun=@(V) P*V;
The indefinite integral of a*x is 1/2*a*x^2 so the definite integrap from b to c would be 1/2*a*(c^2-b^2)
Basically once integrated I need it to look like P2(V3-V2)
That is something that would happen if you were doing not
  2 Kommentare
Areg Arzoomanian
Areg Arzoomanian am 14 Mär. 2020
so if i wanted to make it P2dV how would I change my code?
Walter Roberson
Walter Roberson am 14 Mär. 2020
fun=@(V) P*ones(size(V));
The ones() is important for integral(): integral() will pass in a vector of V values and needs something the same size as V in return.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by