How to solve a second order nonlinear differential equations with a step function

 채택된 답변

Sam Chak
Sam Chak 2022년 6월 14일
편집: Sam Chak 2022년 6월 18일
Edit: The is not signum-based, and the constraint for the velocity is defined in an Event function called velocityEventsFcn.
options = odeset('Events', @velocityEventsFcn);
[t, x, te, xe, ie] = ode23s(@odefcn, [0 10], [0.5 1.5], options);
plot(t, x, 'linewidth', 1.5)
function dxdt = odefcn(t, x)
dxdt = zeros(2, 1);
u = max(0, min(min(100000*x(1) - 99999, 1), min(1, -100000*x(1) + 200001)));
dxdt(1) = x(2);
dxdt(2) = (t + 3*u - (x(2) + t*x(1)^3))/5; % 5*x" + x' + t*x^3 = t + 3*u(x)
end
function [position, isterminal, direction] = velocityEventsFcn(t, x)
position = x(2); % When velocity x(2) = 0,
isterminal = 1; % the integration stops,
direction = 0; % and the velocity cannot go into negative no matter what
end

댓글 수: 13

can you write u different way without using signum function ? and add one more thing that x(2) cant be negative for this whole simulation.
ode45 and related functions are not compatible with discontinuous functions. You would need to stop at the boundaries and restart.
Effective clarification will improve the communication. I have two queries.
Query #1:
Perhaps I interpreted your u(x) incorrectly. It is true that ode45 does not work well with jump discontinuities. Would you enlighten exactly which part of the mathematics that incorrectly describes ? Or, the signum function is disallowed by your Professor? Or, a fancy continuous function is preferred?
x = 0:0.01:3;
u = max(0, min(min(1000*x - 999, 1), min(1, -1000*x + 2001)));
plot(x, u, 'linewidth', 1.5)
grid on
xlabel('x')
ylabel('u')
ylim([-0.5 1.5])
Query #2:
You have mentioned that cannot be negative for the entire simulation. Does your ODE correctly reflect this? The ODE solver only integrates the differential equations that are given. If you can provide a little more critical information about the system that you want to simulate, then it will be helpful in the coding process.
At u(1) and u(2) , It's not mandatory to use ode45 only.
Actually is the velocity then how to put a condition that
@Sudipta Mukherjee, Still waiting for your technical reply on Query #1. Why would you want to avoid using signum function to describe ? Is the newly proposed function acceptable to describe ?
On , we know nothing about the physical dynamics of your system. Either the differential equations are modeled by you, or they come from a reference (your supervisor, books, journal paper, etc.).
then u(1)=u(2)= at boundary as u=(sign(x(1)-1)-sign(x(1)-2))/2;
Thanks for your clarification. Now I see...
If is strictly desired, and the proposed signum-based boxcar function gives , then the requirement is not met.
However, thinking deeper, would x (position) reach or in finite time?
I'm just trying to help and I know that is a piecewise function. What mathematical differentiable function do you suggest for ? Anyhow, I have edited the Answer to run the sim for .
if then what will be the u(x) function in the matlab code?
I did't try, but you can use the non-signum template to design for the new .
u=0
if x(1)>=0 && x(1)<=10^-9
u=1;
end
can i use this?
Yes, go ahead. It can't hurt, at least not more than what you are already doing.
Are you still working on the 5 x'' + x' + t x^3 = t + 3 u(x) just with a different range over which u(x) is 1?
Could you remind us what the boundary conditions are?
options = odeset('Events', @velocityEventsFcn);
[t, x, te, xe, ie] = ode23s(@odefcn, [0 10], [-0.5 1e-5], options);
plot(t, x, 'linewidth', 1.5)
legend({"x'", "x''"})
function dxdt = odefcn(t, x)
dxdt = zeros(2, 1);
u = x(1)>=0 && x(1)<=10^-9;
dxdt(1) = x(2);
dxdt(2) = (t + 3*u - (x(2) + t*x(1)^3))/5; % 5*x" + x' + t*x^3 = t + 3*u(x)
end
function [position, isterminal, direction] = velocityEventsFcn(t, x)
position = x(2); % When velocity x(2) = 0,
isterminal = 1; % the integration stops,
direction = 0; % and the velocity cannot go into negative no matter what
end

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2022년 6월 14일

댓글:

2022년 7월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by