how to solve a set of differential equation systems like this?
42 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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.
Réponse acceptée
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
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
Plus de réponses (1)
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
Sam Chak
le 17 Nov 2022
Modifié(e) : Sam Chak
le 17 Nov 2022
Hi @Daniel Niu
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.
Voir également
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!