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.