problem with matlab function in simulink (inpunt problem)

2 visualizaciones (últimos 30 días)
Alya Bostani el 5 de Abr. de 2024
Respondida: Sam Chak el 6 de Abr. de 2024
im working on a pnuematic simulation , in the simulation i have a pressurized tank with 300 bar at room temperature and its pressure reduces as time goes by thus its temperature ,and there are a gas pressure regulator after the tank im trying to find the temperature drop after the regulator as as the gas expands to do so im assuming that the system is an isentropic system and im using the isentropic expansion equation to find T2 as time goes by T2=T1*(((P2/P1)^((k-1)/k), where k=1.4 , and P2 is a fixed pressure valvue of (40 bar). to do so i tried to use the (matlab function block) but when I introduce 2 none constatnt inputs (P1 & T1 both changes with time) to the block the output is just zero for some reason.
the P1 profile:
the T1 profile:
the matlab function block:
function Tr =fcn(Tt ,Pr,k, Pt)
k=1.4
Pr=40 %bar
Tr =Tt*((Pr/Pt)^((k-1)/k));
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Respuestas (2)

Fangjun Jiang el 5 de Abr. de 2024
Editada: Fangjun Jiang el 5 de Abr. de 2024
From the diagram, "Tt" and "Pt" are the 1st and 2nd input
From the function code, "Tt" and "Pr" are the 1st and 2nd input, while "k" and "Pt" are parameters.
Double check and correct them.
Open the Editor, Mark a breakpoint and run the simlation. When the simulaiton pauses at that breakpoint, check the value and debug it.
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Sam Chak el 6 de Abr. de 2024
Is this the expected result for ? Try fixing the code in the matlabFunction block.
t = 0:0.01:10;
P = asinh(5 - t);
amp = max(P) - min(P);
%% Input 1
Tt = (3/log(1 + exp(5)))*log(1 + exp(5 - t));
%% Input 2
Pt = (230/amp)*asinh(5 - t) + 230/2 + 60;
%% code in matlabFunction block
function Tr = fcn(Tt, Pt)
k = 1.4;
Pr = 40;
Tr = Tt.*(Pr./Pt).^((k - 1)/k);
end
%% Plot results
tL = tiledlayout(3, 3);
nexttile
plot(t, Tt, 'linewidth', 1.5, 'Color', [0.8500, 0.3250, 0.0980]), grid on, title('T_{t}')
nexttile([2 2])
Tr = fcn(Tt, Pt);
plot(t, Tr, 'linewidth', 1.5, 'Color', [0.4660, 0.6740, 0.1880]), grid on, title('T_{r}')
nexttile
plot(t, Pt, 'linewidth', 1.5, 'Color', [0.9290, 0.6940, 0.1250]), grid on, title('P_{t}'), ylim([50 300]), yticks(50:50:300)
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Categorías

Más información sobre General Applications en Help Center y File Exchange.

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by