How to use Matlab to find a pressure in a temperature and density spreadsheet using the nearest density value.

12 visualizaciones (últimos 30 días)
I have a pressure and temperature spreadsheet where pressure is the first column from 14.7 - 2414.7 and temperature is the first row from 65 - 80 and the associated density fills in the rest of the matrix. I am having issues using Matlab to find the pressure associated with an inputed Temperature and Density and I think its due to not having the exact density value. I've tried using an interpolate function and a find function with no luck. If anyone could help solve this issue that would be much appreciated! I havent used Matlab in the last 3 years and am struggling getting back into it. Thanks!
Interpolate code:
newDensity = ((den * V) + ((mdot/(60*60))*ts)/V); %new mass&density in bottle after time step%
%read pressure, Temperature, and density Excel Spread Sheet%
Table = readtable('GBUgasTPDdata.xlsx');
temperature = Table{1,2:end};
pressure = Table{2:end,1};
newPressure = interp1(temperature,pressure,newDensity);
Find Code:
newDensity = ((den * V) + ((mdot/(60*60))*ts)/V); %new mass&density in bottle after time step%
%read pressure, Temperature, and density Excel Spread Sheet%
Table = readtable('GBUgasTPDdata.xlsx');
temperature = Table{1,2:end};
pressure = Table{2:end,1};
xvar = find(temperature==T);
yvar = find(pressure==Pb);
Int = Table{yvar+1, xvar+1}
  2 comentarios
dpb
dpb el 20 de Sept. de 2024
The problem is you need reverse lookup of the P,T intersection of the new density -- presuming that calculation is the reference real new condition.
Is the table by any chance the steam tables data? If so, I'd suggest using the <File Exchange XSteam> submission that has the ASME standard steam tables correlations builtin and can return any desired property given the others.
If it is some other fluid, code for many common ones is also available.
Jessica Langley
Jessica Langley el 20 de Sept. de 2024
Thanks! I think this could be helpful in the future! Right now I am trying to work with oxygen enriched air, so I'm not sure if the specific concentrations are in the steam tables. I was using REFPROP in excel to calculate the temperature and pressure graph because it allows you to adjust concentrations.

Iniciar sesión para comentar.

Respuestas (3)

Star Strider
Star Strider el 20 de Sept. de 2024
It would help to have your data.
Use the scatteredInterpolant function to find (and if desired, plot) any value you want within the ranges of your data.
Try this —
t = linspace(10,30, 25);
p = linspace(1, 20, 20);
[T,P] = ndgrid(t,p);
Z = exp(-((T-20).^2+(P-10).^2)*0.01);
TPfcn = scatteredInterpolant(T(:),P(:),Z(:));
TP_15_10 = TPfcn(15,10) % Find ‘Z’ Value For T = 15, P = 10
TP_15_10 = 0.7788
figure
surf(T, P, Z)
hold on
plot3(15, 10, TP_15_10, 'pc', 'MarkerFaceColor','c', 'MarkerSize',25)
hold off
grid on
xlabel('T')
ylabel('P')
colormap(turbo)
.
  4 comentarios

Iniciar sesión para comentar.


cr
cr el 20 de Sept. de 2024
Editada: cr el 20 de Sept. de 2024
This should be an interpolation in 2 dimensions and should work in a straight forward way unless I missed a key detail in your description.
InterpolatedDensity = interp2(temperature, pressure, densityMatrix,NewTemp,NewPres)
temperature and pressure are the row and column from excel sheet. densityMatrix is the full matrix of density values. NewTemp and NewPres are the temperature and pressure where you want to query the density. There are interp options like nearest, linear, etc that can be used.
  5 comentarios
Jessica Langley
Jessica Langley el 20 de Sept. de 2024
Yes thank you! I ended up just biting the bullet and changing the excel data from pressure vs temperature to density vs temperature and using this method. Thanks again!
dpb
dpb el 20 de Sept. de 2024
It would be most interesting to see the actual data -- how nonlinear is it? It might be feasible to simply replace the whole table with a response surface from which you could calculate directly...

Iniciar sesión para comentar.


Torsten
Torsten el 20 de Sept. de 2024
Editada: Torsten el 20 de Sept. de 2024
%Generate artificial data
t = linspace(10,30, 25);
p = linspace(1, 20, 20);
[T,P] = ndgrid(t,p);
d = exp(-((T-20).^2+(P-10).^2)*0.01);
%Inverse interpolation
tnew = 22.5;
dnew = 0.35;
dcut = interp2(t,p,d.',tnew,p);
%fun = @(x)(interp1(p,dcut,x,'pchip')-dnew)^2;
%pnew = fsolve(fun,mean(p))
[~,idx] = min(abs(dcut-dnew));
pnew = p(idx);
%Compare result
interp2(t,p,d.',tnew,pnew)
ans = 0.3456
dnew
dnew = 0.3500

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by