cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

The return value of this function must match the problem size

JohnBriant
1-Newbie

The return value of this function must match the problem size

Can anyone explain what this error message means - I have an OdeSolve block which is giving me this error, even though it is a copy and paste of another solve block which works, but with different initial conditions.

I have a system of DAE's which I need to solve wrt t (i.e. time). For background, it represents a leadscrew mechanism driven by a torsion spring, with friction and flexure of several components. I have set this up in a solve block, using OdeSolve and it works. However, the solution becomes unstable if I extend the solution interval to be too log (greater than 0.9 seconds). In attempting to solve this I have tried eliminating variables (didn't help), changing tol, the number points etc. Now I am attempting to splice two solve blocks together, by feeding the end conditions from one into the initial conditions for the next. The first solve block would solve the first time period (e.g. 0 to 0.8s) and the second would solve the second. The second is an exact copy of the first, but with the initial conditions of the second set to match the end conditions of the first. And I get "The return value of this function must match the problem size". I tried changing all the variable names (same error).

Can someone tell me what this error message means (it doesn't appear in the help files)?

8 REPLIES 8

John Briant wrote:

Can anyone explain what this error message means - I have an OdeSolve block which is giving me this error, even though it is a copy and paste of another solve block which works, but with different initial conditions.

I have a system of DAE's which I need to solve wrt t (i.e. time). For background, it represents a leadscrew mechanism driven by a torsion spring, with friction and flexure of several components. I have set this up in a solve block, using OdeSolve and it works. However, the solution becomes unstable if I extend the solution interval to be too log (greater than 0.9 seconds). In attempting to solve this I have tried eliminating variables (didn't help), changing tol, the number points etc. Now I am attempting to splice two solve blocks together, by feeding the end conditions from one into the initial conditions for the next. The first solve block would solve the first time period (e.g. 0 to 0.8s) and the second would solve the second. The second is an exact copy of the first, but with the initial conditions of the second set to match the end conditions of the first. And I get "The return value of this function must match the problem size". I tried changing all the variable names (same error).

Can someone tell me what this error message means (it doesn't appear in the help files)?

Sounds like a problem in the original solve block; they can be bears to find.

You'll get a lot more (better and useful) help if you post the file.

Problem is now solved:

Still don't know what the error message means.

But the problem was that the initial conditions for the second solve block were not correct. The first solve block was set up to return the values, and not the first derivatives. I was calculating the first derivatives as a follow-up calculation using a polynomial fit (Savitsky Golay method.) This approach removes numerical noise that the solver was generating. However, the values were not suitable for use as initial conditions for the second solve block. The solution was to make the first solve block return first derivatives, and feed these into the initial conditions for the second solve block.

Thanks for the help, Fred,

John

The fact that you require two solve blocks to extend the time suggests that the original problem is not well formed; odesolve shoould be able to cover the time if the second solve block works.

I would also encourage you to look at rkfixed, rkadapt, etc., the other solvers for differential eqquations. They are more difficult to understand hoow to set up; but the advantage is that they will give you a matrix solutions: the first column is the time step, the second is the position, the third column is the first derivative, and so on. (Odesolve is a wrapper around these solvers with a spline fit of the first two columns.) Reach in and grab the short hair!

Yes, I think that next time I will try and do it the "proper" way.

Cheers,

John

I think the underlying reason I need two solve blocks is that the model moves through different phases. In the first 200 ms, the accelerations and forces are >4 orders of magnitude larger than once it has settled down. I would guess that it can go unstable in such circumstances because the contribution to the error function of the slow-moving part of the simulation is very small and therefore it tolerates errors that are too large.

Does anyone know if it's true that it's going to cause problems if the values change in magnitude to this extent?

Can you psot this file?

Sorry, no.

It is commercially sensitive. Given that it works, I am interested now in learning from the experience/helping others learn. This learning is not valuable enough to spend the time it would take to remove the sensitive material in order to post it.

Thanks for your interest,

John

Try this:

Set up the first ODE loop to solve the full time span (like you did before, and watch it fail again.)

Now, right-click on Odesolve; you should see a pull-down menu with a choice of solver types (Adams,Fixed, Adaptive, Radau). Select Adaptive, I believe you're directing Mathcad to use rkadapt as the solver. As help says rkadapt will vary the step size through the interval to adjust for places where rapid changes are taking place.

As with any numeric solver, you need to take a critical look at your solution to see if it "makes sense."

Luck!

Top Tags