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

2 views (last 30 days)
for 0<=t<=10 solve
5 x'' + x' + t x^3 = t + 3 u(x) where u(x) = 1 for 1<=x<=2
=0 otherwise

Accepted Answer

Sam Chak
Sam Chak on 14 Jun 2022
Edited: Sam Chak on 18 Jun 2022
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 Comments
Walter Roberson
Walter Roberson on 5 Jul 2022
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?
Walter Roberson
Walter Roberson on 5 Jul 2022
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

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!