Implement code for multi range of temperature

조회 수: 3 (최근 30일)
Ahmad AlJuhani
Ahmad AlJuhani 2019년 2월 13일
댓글: Sajeer Modavan 2019년 3월 24일
Hi
I need to execute and plot the below code for range of temperatures (T) instead of one value (T=333)
exampel range of T value between 310 and 350 with 5 incremental steps
clc; clear all; close all;
T =333;
Tc = 369.8;
Tr = T/Tc;
Vr = linspace(0.5,5,500);
funcPr = @(Vr) 8/3 * Tr./(Vr - 1/3) - 3./(Vr.^2);
Pr = funcPr(Vr);
if Tr < 1
Pr_l = 1.0;
vdW_Pr_l = [1 -1/3*(1+8*Tr/Pr_l) 3/Pr_l -1/Pr_l];
v=sort(roots(vdW_Pr_l));
A1 = (v(2)-v(1))*Pr_l - integral(funcPr,v(1),v(2));
A2 = integral(funcPr,v(2),v(3)) - (v(3)-v(2))*Pr_l;
AreaDiff = abs (A1-A2);
while AreaDiff > 0.0001
vdW_Pr_l = [1 -1/3*(1+8*Tr/Pr_l) 3/Pr_l -1/Pr_l];
v=sort(roots(vdW_Pr_l));
funcPr = @(Vr) 8/3 * Tr./(Vr - 1/3) - 3./(Vr.^2);
A1 = (v(2)-v(1))*Pr_l - integral(funcPr,v(1),v(2));
A2 = integral(funcPr,v(2),v(3)) - (v(3)-v(2))*Pr_l;
AreaDiff = abs (A1-A2);
Pr_l = Pr_l - 0.00001;
end
end
% Plot
plot(Vr,Pr); hold all
xlim([0.25 4])
ylim([-0.5 2])
xlabel('Vr')
ylabel('Pr')
plot([0.25 4],[Pr_l Pr_l],'k--')
plot(v(1),Pr_l,'bo',v(2),Pr_l,'bo',v(3),Pr_l,'bo')

답변 (1개)

Sajeer Modavan
Sajeer Modavan 2019년 3월 18일
I don't know what you are looking exactly. I did something here, please let me know is it correct or you need further help
clc; clear all; close all;
T = 310:5:350;
Tc = 369.8;
Tr1 = T./Tc;
Vr = linspace(0.5,5,500);
figure
for ii = 1:length(Tr1)
Tr = Tr1(ii);
funcPr = @(Vr) 8/3 * Tr./(Vr - 1/3) - 3./(Vr.^2);
Pr = funcPr(Vr);
if Tr < 1
Pr_l = 1.0;
vdW_Pr_l = [1 -1/3*(1+8*Tr/Pr_l) 3/Pr_l -1/Pr_l];
v=sort(roots(vdW_Pr_l));
A1 = (v(2)-v(1))*Pr_l - integral(funcPr,v(1),v(2));
A2 = integral(funcPr,v(2),v(3)) - (v(3)-v(2))*Pr_l;
AreaDiff = abs (A1-A2);
while AreaDiff > 0.0001
vdW_Pr_l = [1 -1/3*(1+8*Tr/Pr_l) 3/Pr_l -1/Pr_l];
v=sort(roots(vdW_Pr_l));
funcPr = @(Vr) 8/3 * Tr./(Vr - 1/3) - 3./(Vr.^2);
A1 = (v(2)-v(1))*Pr_l - integral(funcPr,v(1),v(2));
A2 = integral(funcPr,v(2),v(3)) - (v(3)-v(2))*Pr_l;
AreaDiff = abs (A1-A2);
Pr_l = Pr_l - 0.00001;
end
end
plot(Vr,Pr); hold all
xlim([0.25 4])
ylim([-0.5 2])
xlabel('Vr')
ylabel('Pr')
plot([0.25 4],[Pr_l Pr_l],'k--')
plot(v(1),Pr_l,'bo',v(2),Pr_l,'bo',v(3),Pr_l,'bo')
end
Temperature.jpg
  댓글 수: 1
Sajeer Modavan
Sajeer Modavan 2019년 3월 24일
Do you need any further help, accept the answer and close this issue if you don't need any further help.

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

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by