How to solve a second order nonlinear differential equations with two other function in it
조회 수: 1 (최근 30일)
이전 댓글 표시
For ; H'=100,h=10
; where, and
댓글 수: 0
답변 (1개)
Sam Chak
2022년 6월 15일
편집: Sam Chak
2022년 7월 5일
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
Sam Chak
2022년 7월 5일
편집: Sam Chak
2022년 7월 5일
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')
참고 항목
카테고리
Help Center 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!