problem with matlab function in simulink (inpunt problem)

31 visualizzazioni (ultimi 30 giorni)
Alya Bostani
Alya Bostani il 5 Apr 2024 alle 14:46
Risposto: Sam Chak il 6 Apr 2024 alle 5:35
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:tank-pressure-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));

Risposte (2)

Fangjun Jiang
Fangjun Jiang il 5 Apr 2024 alle 15:45
Modificato: Fangjun Jiang il 5 Apr 2024 alle 16:37
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.

Sam Chak
Sam Chak il 6 Apr 2024 alle 5:35
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)

Categorie

Scopri di più su General Applications in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by