how to solve a set of differential equation systems like this?

42 次查看(过去 30 天)
Dear friend,
How to solve a ordinary differential equation systems like above using MATLAB?
a=b=c=1
Your help would be highly appreciated.
  4 个评论
John D'Errico
John D'Errico 2022-11-16
编辑:John D'Errico 2022-11-16
Actually, the point where you identify a singularity is an interesting one, since in order for a singularity to exist, one would need to have
x^2 + (c*t-y)^2 == 0
And that implies two things MUST happen, x==0, AND y = c*t. Note that both differential equations have a corresponding term in the denominator. But then look carefully. In the numerator of both equations, they have a similar term on top. As such, that fraction is actually going to have a finite limit at that point. At the exact point of interest, the result is effectively a Nan, but everywhere else, it is well defined. Not really any different from the fraction x/x.

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2022-11-17
编辑:Torsten 2022-11-17
ar = 0.01;
af = 0.001;
x0 = 3;
y0 = -3;
Lr = 0;
Lf = 0;
z0 = [x0; y0; Lr; Lf];
[T,Z] = ode45(@(t,z)fun(t,z,ar,af),[0 11.5],z0);
plot(Z(:,1),Z(:,2),Z(:,3),zeros(size(T)))
ylim([-3 0.5])
function dz = fun(t,z,ar,af)
x = z(1);
y = z(2);
Lr = z(3);
Lf = z(4);
sr = exp(-ar*Lr);
sf = exp(-af*Lf);
dz = zeros(4,1);
dz(1) = sf* (Lr-x)/sqrt((Lr-x)^2+(0-y)^2);
dz(2) = sf* (0-y)/sqrt((Lr-x)^2+(0-y)^2);
dz(3) = sr;
dz(4) = norm([dz(1) dz(2)]);
end
  2 个评论
Daniel Niu
Daniel Niu 2022-11-18
Dear Torsten,
Sorry to bother you again. I want to know if the rabbit is not moving horizontal but from (0,0) to (-100,100)
how to modify the code?
Thank you!
Torsten
Torsten 2022-11-18
编辑:Torsten 2022-11-18
Uninteresting case since both fox and rabbit will run on the same straight line.
ar = 0.01;
af = 0.001;
x0r = 0;
y0r = 0;
x0f = 3;
y0f = -3;
Lr0 = 0;
Lf0 = 0;
z0 = [x0r; y0r; x0f; y0f; Lr0; Lf0];
[T,Z] = ode45(@(t,z)fun(t,z,ar,af),[0 11.5],z0);
plot(Z(:,1),Z(:,2),Z(:,3),Z(:,4))
function dz = fun(t,z,ar,af)
xr = z(1);
yr = z(2);
xf = z(3);
yf = z(4);
Lr = z(5);
Lf = z(6);
sr = exp(-ar*Lr);
sf = exp(-af*Lf);
dz = zeros(6,1);
dz(1) = sr* (-1/sqrt(2));
dz(2) = sr* (1/sqrt(2));
dz(3) = sf* (xr-xf)/sqrt((xr-xf)^2+(yr-yf)^2);
dz(4) = sf* (yr-yf)/sqrt((xr-xf)^2+(yr-yf)^2);
dz(5) = norm([dz(1) dz(2)]);
dz(6) = norm([dz(3) dz(4)]);
end

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2022-11-17
Hint:
The length L(t) of a curve in parametric form (x(t),y(t)) where x(t) and y(t) are given by differential equations
dx/dt = f(x,y)
dy/dt = g(x,y)
can be computed by additionally solving a differential equation for L:
dL/dt = sqrt(f(x,y).^2+g(x,y).^2)
with initial condition
L(0) = 0.
  5 个评论
Torsten
Torsten 2022-11-17
编辑:Torsten 2022-11-17
r1 is part of your ODE system:
dz1/dt = s_f* (r1-z1)/sqrt((r1-z1)^2+(r2-z2)^2)
dz2/dt = s_f* (r2-z2)/sqrt((r1-z1)^2+(r2-z2)^2)
And I think the speed of the rabbit will also decrease with time...
Sam Chak
Sam Chak 2022-11-17
编辑:Sam Chak 2022-11-17
Your original "Fox-chasing-Rabbit" example assumes that the Rabbit is moving at a constant velocity . That's why the solution for the Rabbit's position is .
If the Rabbit's velocity is time-varying, or is reactively dependent on the position of the Fox {, }, then naturally there exists , and I think that is what @Torsten tried to tell you.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Applications 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by