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

42 vues (au cours des 30 derniers jours)
Daniel Niu
Daniel Niu le 16 Nov 2022
Modifié(e) : Torsten le 18 Nov 2022
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 commentaires
John D'Errico
John D'Errico le 16 Nov 2022
Modifié(e) : John D'Errico le 16 Nov 2022
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.
Sam Chak
Sam Chak le 16 Nov 2022
@John D'Errico, Thank you for pointing out this and the explanation.

Connectez-vous pour commenter.

Réponse acceptée

Torsten
Torsten le 17 Nov 2022
Modifié(e) : Torsten le 17 Nov 2022
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 commentaires
Daniel Niu
Daniel Niu le 18 Nov 2022
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 le 18 Nov 2022
Modifié(e) : Torsten le 18 Nov 2022
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

Connectez-vous pour commenter.

Plus de réponses (1)

Torsten
Torsten le 17 Nov 2022
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 commentaires
Torsten
Torsten le 17 Nov 2022
Modifié(e) : Torsten le 17 Nov 2022
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 le 17 Nov 2022
Modifié(e) : Sam Chak le 17 Nov 2022
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Applications dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by