ODE Solver Not Responding to Inputs

3 vues (au cours des 30 derniers jours)
John
John le 27 Août 2011
I have an issue I need to sort out with ode45 in MATLAB. This is a 'test case' for a very large project I am working on which is having this issue. It is easier to explain on a simpler problem.
I have created a program which models two vehicles which have a tow-rope between them. I want to impart a specific velocity on the front vehicle to 'forcefully drive' it. Below is the DE's in the rates of change file:
xd = zeros(4,1);
xd(1)=x(2);
xd(2)=-(k/M1).*(x(1)-x(3))-(120/M1).*sign(x(2)).*abs(x(2))^2+f1/M1;
xd(3)=x(4);
xd(4)=(k/M2).*(x(1)-x(3))-(800/M2).*sign(x(4)).*abs(x(4))^2-f2/M2;
Then to 'drive' the front vehicle I add after this:
if t>0 && t<20
xd(1) = 1*t;
xd(2) = 1;
else
xd(1) = 0;
xd(2) = 0;
end
So I reason that the front car will accelerate at a constant rate (2m/s) then come to an instant stop at 20 seconds.
On the plot produced the velocity of the front car does not stop; it just holds a constant value. However, the car behind acts as if the front car has stopped!
Also, when I un-comment the 'driving' lines I do not get zero:
else
xd(1) = 0
xd(2) = 0
end
Basically the above 2 lines are not being implemented. Your advice is much appreciated.
  2 commentaires
Fangjun Jiang
Fangjun Jiang le 27 Août 2011
Your code is not sufficient enough for us to see the problem.
John
John le 27 Août 2011
Updated. I can not get MATLAB to simulate 'forced motion' on the car.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 27 Août 2011
I still do not get the actual problem. Is it correct that it is described by:
"On the plot produced the velocity of the front car does not stop; it just holds a constant value. However, the car behind acts as if the front car has stopped!"
So it might be possible, that the production of the plot is wrong? Or the interpretation of how the car acts or the expectation how it should act? Or do you think, that the velocity and position calculated by the intergator do not match?
Another problem: The ODE45 (from the text, or ODE23 as in the code) integrator needs a smooth function, because it evaluates the ODE at several intermediate times for each step to estimate the average slope. If some time steps are before and some are behind your time switching points. Therefore all functions, which destroy the continuity, are a bad idea in the ODF function: IF, SIGN, ABS, MIN, MAX, RAND, ...
And finally I do not understand, why you create xd(1) and xd(2) and overwrite it some lines later.
  1 commentaire
John
John le 31 Août 2011
Yes, due to large 'jumps' the ODE solver was not able to operate properly.

Connectez-vous pour commenter.

Plus de réponses (2)

Lucas García
Lucas García le 27 Août 2011
I suggest that you debug your code from t>20 on by setting a conditional breakpoint at
if t>0 && t<20
To do this, after setting a breakpoint, right click it and go to "Set/Modify condition". Then place the condition
t > 20
Now you will be able to debug whenever t>20. Let see what happens.
  1 commentaire
John
John le 27 Août 2011
Can you please explain this further? I am not very familiar with de-bugging methods in MATLAB.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 27 Août 2011
According to the documentation,
Function f = odefun(t,y), for a scalar t and a column vector y, must return a column vector f corresponding to f(t,y)
Your code does not appear to be doing that: your code appears to be returning a fixed size output vector for which the third and 4th outputs are not set according to the time in a manner consistent with the first 2.
The behavior you are seeing in whatever routine you are in would appear to be consistent with the possibility that t is a vector instead of a scalar... though in such a case I would expect an error about the use of && with a vector.
  2 commentaires
John
John le 27 Août 2011
Thank you for your reply. I think what you are saying may be the clue to solving this problem. I have posted the full code for viewing above. Can you please explain further how to correct this issue?
Walter Roberson
Walter Roberson le 27 Août 2011
Darn, the documentation confuses me; it looks like I was misinterpreting it.
Sorry, this is not something I have time to work on at present.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by