How to solve a second order nonlinear differential equations with two other function in it
Show older comments
For
; H'=100,h=10

Answers (1)
3rd Edit: The simulation. I re-scaled
and
so that you can see the inputs
and 
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);
Ua = 1*((0 < x(1)) & (x(1) <= 0.5)); % segment 1
Ub = 0*((x(1) <= 0) & (0.5 < x(1))); % segment 2
U = Ua + Ub; % piecewise U(x)
h = 1;
H1 = 3;
Ha = (H1*t/h).*((0 <= t) & (t < h)); % segment 1
Hb = H1*(h <= t); % segment 2
H = Ha + Hb; % piecewise H(t)
dxdt(1) = x(2);
dxdt(2) = (t + H + (x(1) + t)*U - (x(2) + t*x(1)^3))/5;
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

2nd Edit: A new
function as per request. There are just straight lines and linear geometry. You can definitely calculate them.
h = 1e-9;
t = linspace(0, 2*h, 20001);
H1 = 100;
H = (H1*t/h).*max(0, min(min(1e12*(t - (0*1e12 - 1)/1e12), 1), min(1, -1e12*(t - (h*1e12 + 1)/1e12)))) + H1*max(0, min(1e12*(t - h), 1));
plot(t, H, 'linewidth', 2), grid on, ylim([-0.2*H1 1.2*H1]), xlabel('t'), ylabel('H')
1st Edit: After you edited the question, this is one way to describe the
function without using the signum function (as in your previous question). The formula is valid so long as
. For
, you can design it using the template given in the proposed max–min function in your previous question.
t = linspace(0, 20, 20001);
h = 10;
H1 = 100;
H = (H1/h)*max(0, min(100000*t, 1)) + (H1 - H1/h)*max(0, min(100000*(t - h), 1));
plot(t, H, 'linewidth', 2), grid on, ylim([-2*H1/h H1+2*H1/h]), xlabel('t'), ylabel('H')
-----------
Since there is no response or reply to the proposed solution in the other Question posted yesterday with exactly the same dynamics, then it implies that probably the tricks have been learned to solve similar problem. If fact, this problem is probably simpler than the other because the simulation time is up to
.
.9 Comments
Sudipta Mukherjee
on 16 Jun 2022
Edited: Sudipta Mukherjee
on 2 Jul 2022
Sudipta Mukherjee
on 2 Jul 2022
Sam Chak
on 2 Jul 2022
Thought you have found your own solutions since no reply two weeks ago. By the way, can we have a closure on the following relevant question first? I have edited the Answer a few times to fulfil your requirements of (1) not using the signum function, and (2) velocity is non-negative
.
Thanks for your consideration on this matter.
Sudipta Mukherjee
on 4 Jul 2022
Sam Chak
on 4 Jul 2022
I have design the function for
. You can refer to the solution in your previous to design
.
If you have trouble, show your code and let me see how to fix it.
Sudipta Mukherjee
on 5 Jul 2022
Dear @Sudipta Mukherjee
We cannot be absent-minded when dealing with engineering problems. One small mistake can make someone get electrocuted (electrical failure), a building collapses (civil structural failure), or a place crash (mechanical failure), or even lead to the disintegration of a spacecraft (domino-effect system failure).
Even if this is an academic project for you, you must train yourself to handle math and coding with meticulous care. Don't rely on your supervisor to nudge or remind you.
Sudipta Mukherjee
on 5 Jul 2022
It's okay. Everyone is a learner at some point in life. I have included the code in the edited Answer.
If you find the MATLAB code is helpful, please consider accepting ✔ and voting 👍 the Answer. Thanks!
If you want to use logic, then this approach should be easier for you.
h = 1e-9;
t = linspace(0, 2*h, 20001);
H1 = 100;
Ha = (H1*t/h).*((0 <= t) & (t < h)); % segment 1
Hb = H1*(h <= t); % segment 2
H = Ha + Hb; % combine two segments
plot(t, H, 'linewidth', 2), grid on, ylim([-0.2*H1 1.2*H1]), xlabel('t'), ylabel('H')
Categories
Find more on Troubleshooting in Simulink Real-Time 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!


