Help With Integrating a function with certain bounds

조회 수: 2 (최근 30일)
Areg Arzoomanian
Areg Arzoomanian 2020년 3월 14일
댓글: Walter Roberson 2020년 3월 14일
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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 3월 14일
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
Areg Arzoomanian
Areg Arzoomanian 2020년 3월 14일
so if i wanted to make it P2dV how would I change my code?
Walter Roberson
Walter Roberson 2020년 3월 14일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by