Code needs to display:
Code is displaying a blank graph.
clear,clc
R=8.314; T1=60+273.15; PvapH=.7583;PvapT=.3843;HvapH=29000;HvapT=31000;P=.7;
fPvapH1=@(T2) PvapH*exp(-1*HvapH/R*((1./T2)-(1/T1)));
fPvapT1=@(T2) PvapT*exp(-1*HvapT/R*((1./T2)-(1/T1)));
fxH=@(x) (x*PvapH/P)+((1-x)*PvapT/P)-1;
xH=fzero(fxH,.7);
xT=1-xH;
fBPH=@(T2) (((xH*fPvapH1(T2))/P)+((xT*fPvapT1(T2))/P))-1;
BPH=fzero(fBPH,340);
yH=xH*fPvapH1(BPH)/P;
yT=xT*fPvapT1(BPH)/P;
T=linspace(55,80,100);
figure(1)
plot(xH,fBPH(T))
hold on
plot(yH,fBPH(T))
hold off
axis([0 1 55 80])

5 comentarios

  • xH and yH are not vectors
  • this T should be in celcius or kelvin? it returns -1 -1 -1 -1...
R=8.314; T1=60+273.15; PvapH=.7583;PvapT=.3843;HvapH=29000;HvapT=31000;P=.7;
fPvapH1=@(T2) PvapH*exp(-1*HvapH/R*((1./T2)-(1/T1)));
fPvapT1=@(T2) PvapT*exp(-1*HvapT/R*((1./T2)-(1/T1)));
fxH=@(x) (x*PvapH/P)+((1-x)*PvapT/P)-1;
xH=fzero(fxH,.7)
xH = 0.8441
xT=1-xH;
fBPH=@(T2) (((xH*fPvapH1(T2))/P)+((xT*fPvapT1(T2))/P))-1;
BPH=fzero(fBPH,340);
yH=xH*fPvapH1(BPH)/P
yH = 0.9144
yT=xT*fPvapT1(BPH)/P;
T=linspace(55,80,100);
fBPH(T)
ans = 1×100
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Angelina Encinias
Angelina Encinias el 10 de Mzo. de 2022
I attached the graphs that the code should display. I am unsure if I need for loops.
Angelina Encinias
Angelina Encinias el 10 de Mzo. de 2022
T should be Celsius
Torsten
Torsten el 10 de Mzo. de 2022
In the equation
fxH=@(x) (x*PvapH/P)+((1-x)*PvapT/P)-1;
all parameters are given constants except x.
But PvapH and PvapT should depend on T, I guess.
Angelina Encinias
Angelina Encinias el 10 de Mzo. de 2022
This is the question. I am pretty sure I need a for loop to display the graphs.

Iniciar sesión para comentar.

 Respuesta aceptada

Torsten
Torsten el 10 de Mzo. de 2022
Editada: Torsten el 11 de Mzo. de 2022

0 votos

R = 8.314;
T1 = 60 + 273.15;
PvapH = .7583;
PvapT = .3843;
HvapH = 29000;
HvapT = 31000;
P = .7;
fPvapH = @(T) PvapH*exp(-HvapH/R*(1./T - 1/T1));
fPvapT = @(T) PvapT*exp(-HvapT/R*(1./T - 1/T1));
XH = 0:0.01:1;
Tstart = 340;
for i=1:numel(XH)
xH = XH(i);
fun = @(T) xH*fPvapH(T)/P + (1-xH)*fPvapT(T)/P - 1;
T(i) = fzero(fun,Tstart);
Tstart = T(i)
end
YH = XH.*fPvapH(T)/P;
XT = 1-XH;
YT = XT.*fPvapT(T)/P;
T = T - 273.15;
figure(1)
plot(XH,T)
hold on
plot(YH,T)
hold off
axis([0 1 55 80])
figure(2)
plot(XT,T)
hold on
plot(YT,T)
hold off
axis([0 1 55 80])

Más respuestas (1)

Benjamin Thompson
Benjamin Thompson el 10 de Mzo. de 2022

0 votos

xH, yH, and BPH are all scalar values. They must be the same length as fBPH(T). In this line to you mean to pass a vector argument to the fxH function handle?
xH=fzero(fxH,.7);

2 comentarios

Angelina Encinias
Angelina Encinias el 10 de Mzo. de 2022
Yes I did. The graph is supposed to look like the graph on the left (image I attached). To make the image on the right I need to do yH(xH).
Angelina Encinias
Angelina Encinias el 10 de Mzo. de 2022
Image of graphs needed to display is attached.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 10 de Mzo. de 2022

Editada:

el 11 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by