Skip to main content
10-Marble
June 18, 2025
Solved

Simulation ODE with time functions

  • June 18, 2025
  • 4 replies
  • 2801 views

Good morning, everyone,

I'm currently working on a Mathcad sheet. I have two time-dependent functions that I want to combine with a differential equation. However, I keep getting an error message, and I'm not sure what I'm doing wrong.

I managed to get it working in MATLAB, but I would like to finish this properly in Mathcad. The issue occurs on the last page, where the solve block isn't isolated from the rest of the calculations 

Does anyone know how I can solve this? Thanks in advance!

Best answer by Werner_E

You do it exactly as you did 😉

And the name of the formal argument (currently x2) when you define function p.gas does not matter at all.

The error message is not helpful at all. The reason is a unit mismatch.

You defined p.gas0 to be 8*10^6, but it should be 80 bar. Actually I forgot to add the unit in the sheet where I tried to use units allover.

Not sure why this unit mismatch did not show in the sheet I posted - maybe because the else branch in the definition for x2'' never was called!?

I also noticed in that older sheet that the usage of function k.gas also would result in a unit mismatch even with the correct unit for p.gas0:

Werner_E_0-1750685936984.png

 

Anyway, in your new sheet k.gas is not used and once you add the correct unit for the initial gas pressure the solve block works OK.

 

Prime 10 sheet attached

4 replies

23-Emerald IV
June 18, 2025

1st. You should state that you are using Prime 5, to prevent that you get an answer in prime 6...11 which you cannot open.

2nd. See what happens if you remove the " x''(t)= " from the "else" part in your constraint.

Phrased as it is now, your constraint sets x''(t) to be either 0 when the IF condition is true, or it is the result of the boolean expression in the else part.

 

Success!
Luc

10-Marble
June 18, 2025

Hi Luc,

Thanks for the quick reply. I’m indeed working in Prime 5 (although I recently gained access to Prime 10 as well). I removed the x''(t)= part from the else branch exactly as you suggested, but unfortunately, I’m still getting the same “Argument not specified” error.

25-Diamond I
June 18, 2025

1) You should use x1 and x2 in the odesolve command, not their derivatives.

 

2) p.gas is a variable (value 8*10^6) but is used as if it was a function here on the LHS.

Werner_E_0-1750246443403.png

This can't work

 

3) k.gas is here used like a function but its nowhere defined, neither as a function nor as a variable

Werner_E_1-1750246541455.png

The same undefined variable (k.gas) also occurs in the else branch in the definition of x.2''

 

Simply deleting the undefined expressions makes the solve block work, but sure that's not what you ar looking for. Of course x2 is constant zero.

Werner_E_2-1750247156362.png

I am not sure if the solve block will work using the branching (if ... else) on the RHS but as a first step you have to fix the problems with p.gas and k.gas.

 

10-Marble
June 18, 2025

Hi Werner,

Thanks again for the detailed feedback!

Since my last message, I made this model in the past in Python  (slightly different parameter set), and that version solves without errors, so the core equations do work. I linearized the orifice equation using the chain rule, but the overall structure remains the same.I’ll walk through the sheet once more and, line by line, compare it with the Python code to spot the mistake and your remarks below

I’ve already:

  1. switched the odesolve vector to use x1 and x2 (not their derivatives sorry );

  2. renamed the scalar p_gas to p_gas0 and added a proper p_gas(x) function;

  3. introduced the missing k_gas(x) definition. ( Gas stiffness as a function of the position of x2)

With those changes the solve block runs, but the results still look off. I’ll keep checking and let you know what I find to solve this, maybe you can see my mistake in one eye blink. The function shared by you was my initial starting point see sheet ref 12 working fine. The add on was the extra motion equation for the accumulator. Thanks a lot for your help so far it’s really appreciated! 

AD_10780197_1-1750251761725.png

 

25-Diamond I
June 18, 2025

@AD_10780197 wrote:

I’ve already:

  1. switched the odesolve vector to use x1 and x2 (not their derivatives sorry );

  2. renamed the scalar p_gas to p_gas0 and added a proper p_gas(x) function;

  3. introduced the missing k_gas(x) definition. ( Gas stiffness as a function of the position of x2)

Hmm, I loaded your "A14" sheet and you did NOT changed the variables/function you solve for in the odesolve block
You renamed p_gas to p_gas0 but you did not defined functions p_gas and k_kas. You used boolean expressions inside the solve block and not function definitions in front of it as shown in my previous answer below.

See the attached Prime 10 sheet.

PS: I noticed that in the A12 sheet you provided you tried to use units in the plot. To do so you should use units right from the start!

Or you redefine like x1(t):=x1(t)*1/bar, but using units throughout sure is preferable.

 

25-Diamond I
June 18, 2025

Could it be that you had something like the following in mind?

I defined a function k.gas in front of the solve block so it could be used in the definition of x2''. I had no idea what you had in mind with your "function" p.gas, so I deleted it and just used the already defined variable p.gas as you had set it up.

vgas and v1 are defined after the solve block using the results for x1 and x2. x2 still seems to be constant zero.

Werner_E_0-1750248656450.png

 

10-Marble
June 19, 2025

Dear Werner,

Thanks again — I’ve made good progress due to you, and the system is almost working as expected. When I add an extra differential equation based on the conservation law (mass balance), everything still works correctly and behaves as expected. See the named working as the latest extension name in the attachment

 

However, when I try to make the gas pressure and gas stiffness explicitly dependent on the dynamic motion of x2(t), the model starts to fail. It simply stops working as expected. I’ve double-checked the free-body diagram. I know that in steady-state, the pressures should be balanced, so this behavior is unexpected

 

 I will try to solve this, maybe you have some tips. Perhaps the issue is due to the highly nonlinear nature of the gas-related functions (as shown in the appendix). I’m considering linearising the expressions for gas stiffness and gas volume to improve stability. It’s also unclear whether this inconsistency only affects the transient phase or if it also has an impact in steady-state conditions.

 

Best regards,

 

Albert 

25-Diamond I
June 20, 2025

However, when I try to make the gas pressure and gas stiffness explicitly dependent on the dynamic motion of x2(t), the model starts to fail.

I looked at your "almost" file but found no failing calculation ?

Community Moderator
June 25, 2025

Hello @AD_10780197,

 

It looks like you have some responses from our community champion. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution. 

Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Vivek N.
Community Moderation Team.