ODE45 randomly returns vector of length 1.
Show older comments
I am solving ODEs with a script I run many times, and often what is happening is that I can run it several times sucessfully while changing parameter values every time, but then all of the sudden I get the error "script returns a vector of length 1,..." and then I can't run the script again because I keep getting this error. This has happened me seemingly randomly multiple times, and I can usually shut my computer down and either the next day or two, the error just stops happening even though I do not make any changes to the code.
Is this something that happens to other people, and am I missing something obvious? I could include my script if that helps, but this error happens to me with almost every ODE script I have to run multiple times while changing parameter values.
Thanks for any help.
EDIT: My files are included in the comments. When I call the ODE file, I get the error that the returned vector is of length of 1, but when I just compute the dxdt explicitly from the ODE file, I obtain a vector of length 3 so I'm not sure where the problem is.
2 Comments
Cesar García Echeverry
on 28 Apr 2020
Can you share your code? Maybe is a problem definition.
Noah Bolohan
on 28 Apr 2020
Answers (2)
James Tursa
on 28 Apr 2020
Edited: James Tursa
on 28 Apr 2020
0 votes
Try clearing your variables before you run the script. It could be that you are inadvertently using a variable from a previous iteration.
1 Comment
Noah Bolohan
on 28 Apr 2020
John D'Errico
on 28 Apr 2020
If it happens with almost every script that you run, though not immediately, then it is something you are doing that is strange, because that is not behavior anyone else ever sees. Passing variables around using globals is always dangerous as hell, because it make things difficult to debug. I'm not sure where the problem arises, but I would suggest using the debugger. Set it to trap out when an error occurs. Then look very carefully at the variables involved, at how the functions are called. You may need to wander around in the stack to figure out the problem, but this is certainly not anything I have ever seen or heard of. And since you do not appear to be doing anything overtly dangerous with memory, that means you have done something nasty in the code.
If I had to make a guess, I wonder if possibly globals are indeed causing your problem. clear all should kill them off. But you have created something strange here, and the most likely cause seems to be the heavy use of globals.
So you might add an additional call to clear at the beginning to test this out:
clear GLOBAL
Though I do see this claim in the help for clear.
clear ALL removes all variables, globals, functions and MEX links.
Using the debugger is the only viable way to track it down.
1 Comment
Noah Bolohan
on 29 Apr 2020
Edited: Noah Bolohan
on 29 Apr 2020
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!