Skip to main content
10-Marble
March 18, 2014
Solved

ODE with two functions of time

  • March 18, 2014
  • 1 reply
  • 5143 views

There may be a trick to solving this ODE but I am at a loss. All I can assume is that it is something to do solving 2 functions simultaneously but in my view the only linkage between these functions is time otherwise I believe they should be independent in terms of depth h because the depths in the tank and the weir are only related indirectly by way of inflow. As you can see I am getting an error. The problem looks simple enough i.e. fill a tank with water and then drain the water out at the bottom of the tank at a slower rate than the infill rate. By definition the tank should fill with water to a certain height.The complexity is that the inflow is by way of a weir. The inflow from the weir increases with the depth of flow. I(h). The outflow is a function of the depth of water in the tank Qout(hw). But as you can see the ODE fails but I don't know why?

Can someone show me how this can be done?

Thanking you in advance.

Mark

Best answer by Werner_E

it looks like you can use ODE solve blocks as functions

Yes you can turn any solve block in a function. E.g. you may provide the necessary guess value for a given-find() block as parameter, etc. YOu may also rewrite the block to accomodate for a weir height which is not constant over time. in the block replace h by h(t). To test it, define a function hh(x):=150mm and define h(index)w150:=h(index)w(hh). You get the same function h(index)w150 as before.

provided the variable that you want to find is not also a function.

What the odesolveblock is trying to find IS a function (h(index)w) - its not a variable!?

Why is it that you had to create a function with 2 arguments.

Its a new limitation of Prime or I haven't found out how to do it otherewise. I'm not used to Prime as I don't use it for anything serious. In Mathcad 15 you would not have to define that auxiliary function, you could use h(index)w() the same way as h.w() directly.

I would have thought that the ODE solve block function hw(h) contained the solution vectors for both the variable Hw and t. However when I try to calculate this function in isolation I get the following:

What does all that all mean looks like some error code?

What odesolve returns is not just a solution vector - its that vector of discrete function values coupled with an implicit interpolation. The result of odesolve can be used numerically like a normal function. Without turning the block into a function, when we wrote hw:=odesolve(...) you can use the result like a function, typing hw(12 s)=... or plotting it like you had defined it analytically. So when you simply type hw= Prime tells you in its charming way that its a function - thats not an error message. The same happens now when you evaluate h(index)w(150mm)=... So to evaluate that function for time 10s it would be necessary to write h(index)w(150mm)(10s)=... The first parenthesis being the argument for the solve block function which returns a function and the second parenthesis for the argiment of this new function. This syntax doesn't work, though but in MC15 we are allowed to write h(index)(150mm,10s)=.., in Prime we are not allowed to do so and that the reason for that auxiliary function.

The "error" you get in the attached pic is simply eyplained. h at that moment is not undefined but one of your range variables. The range acts like an implicit for-loop feeding one value after the other in the solve block and getting back a function each time. So it presents you the result telöling you that the expression you want to evaluate is a list of functions.

It seems strange that the Solve Block does not return a user accessible solution vectors i.e. ones that can be inspected directly.

If you want use the solution vectors and do the interpolation to turn it into a function yourself, you have to use one of the standalone ODE solvers. That way you have also control over the method used (we could chose the method in MC15 for odesolve, too, but this feature is gone with Prime), odesolve uses Adams/BDF and I am not sure if it switches automatically to another method if necessary. The help mentions in "Algorithms for ODEs" the other methods, but I think this is simply a left overer from turning the MC15 help, where we could chose the method) into the Prime help. The syntax for the standalone solvers may be a bit cumbrous but if you want to see the vectors thats the way to go. Look them up in the help or any other documentation you have at hand. http://www.ptc.com/cs/help/mathcad_hc/prime3_hc/mprime/ode_solvers.html?queryId=144d98fae6b

Is not this the whole purpose of an ODE i.e. we are solving for a function

Are we? Then you have to use odesolve as you already did. This gives you a function but not the data vector behind it. Basically odesolve gives you the same as Adams() or BDF() followed by an lspline interpolation.

1 reply

25-Diamond I
March 18, 2014

But as you can see the ODE fails but I don't know why?

Because you use I(h(t)), but h is at that time not a function of time but a range variable. Thats the reason for the error.

You haven't set up an equation showing the depth of flow in dependence of time.

10-Marble
March 18, 2014

Werner;

Is not the Qout(hw) also not a function of time? As it too uses a range variable to kick off the calculation. I can see physically at least how Qout(hw) is weakly related to time as it takes time to fill the tank to each new value of hw which in turn increases the outflow as Qout(hw) gets larger with depth. However I see no way of linking the inflow with time as it seems independent except to say that an increasing depth of flow over the weir gives a greater inflow. All I am doing is describing how the inflow varies with h (aka a hydraulic rating curve) but I don't see a way to link this with time?

Although what I believe may be incorrect I was of the belief that the ODE solve block was the structure that created the function of time for both functions inflow and outflow. Anyway it should produced function(s) that describe how the height of the water varies in the tank with time and as a consequence one can then calculate the outflow function which may at times be leveling off or in some cases decreasing if the outflow proved to be greater than inflow.

So where to now? because my feeling is that the inflow although it varies with the height of water above the weir seems not to be coupled with the volumetric storage capacity of the tank. Or maybe once again describing this situation mathematically eludes me.

Regards, Mark

25-Diamond I
March 18, 2014

The problem in your solveblock is that you use a function h(t) which you did not define anywhere. This is why the solve block is throwing an error. If you use a function you either have to define it prior or solve for it in an ode solve block (like you do with h.w).

As you write you thought that odesolve would take care of h(t) I ma ask - how?? If you want odesolve to solve for h(t), too, you have to set up the block to solve for both functions. That way you would have tp provide one additional equation and an initial value.

I guess you must make clear to yourself whats given and what you are searching for.