ODE Solver Not Responding to Inputs

조회 수: 3 (최근 30일)
John
John 2011년 8월 27일
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
Fangjun Jiang
Fangjun Jiang 2011년 8월 27일
Your code is not sufficient enough for us to see the problem.
John
John 2011년 8월 27일
Updated. I can not get MATLAB to simulate 'forced motion' on the car.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 8월 27일
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
John
John 2011년 8월 31일
Yes, due to large 'jumps' the ODE solver was not able to operate properly.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Lucas García
Lucas García 2011년 8월 27일
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
John
John 2011년 8월 27일
Can you please explain this further? I am not very familiar with de-bugging methods in MATLAB.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 8월 27일
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
John
John 2011년 8월 27일
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 2011년 8월 27일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by