How to solve a second order nonlinear differential equations with a step function
显示 更早的评论
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
采纳的回答
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
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)=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.
is strictly desired, and the proposed signum-based boxcar function gives 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 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
