Determine where lines intersect

1 vue (au cours des 30 derniers jours)
Andreas
Andreas le 29 Sep 2014
Commenté : Jan le 5 Oct 2014
Hey! Im wondering how i could Determinate the intersect of these two lines. I got the following code.
z0=10000;
dz0=0;
span=[0 250];
[T,Y] = ode45(@function_A,span,[z0 dz0]);
x=linspace(0,300,2000);
plot(T,Y(:,1),'b', x,0,'g');
and this function
function dz = function_A(t,z)
dz = zeros(2,1);
g=9.81;
m=250;
lambda=7.5*10^3;
k0=(m*g)/((250/3.6)^2);
k=@(z)k0.*exp(-z./lambda);
dz(1)=z(2);
dz(2)=-g-(k(z(1)).*abs(z(2))*z(2))/m;
end
Anyone who can help me?

Réponses (1)

Mischa Kim
Mischa Kim le 29 Sep 2014
Modifié(e) : Mischa Kim le 29 Sep 2014
Hello Andreas, use ode events. This examples shows how to detect events with the bouncing ball problem. Check out the following:
function my_ode()
z0 = 10000;
dz0 = 0;
span=[0 250];
options = odeset('Events',@events);
[T,Y,Te,Ye,Ie] = ode45(@function_A,span,[z0 dz0],options);
x = linspace(0,300,2000);
plot(T,Y(:,1),'b', x,0,'g');
end
function dz = function_A(t,z)
dz = zeros(2,1);
g = 9.81;
m = 250;
lambda = 7.5*10^3;
k0 = (m*g)/((250/3.6)^2);
k = @(z)k0.*exp(-z./lambda);
dz(1) = z(2);
dz(2) = -g-(k(z(1)).*abs(z(2))*z(2))/m;
end
function [value,isterminal,direction] = events(t,y)
% Locate the time when height passes through zero in a
% decreasing direction and stop integration.
value = y(1); % Detect height = 0
isterminal = 1; % Stop the integration
direction = 0; % Negative direction only
end
  1 commentaire
Jan
Jan le 5 Oct 2014
The function to be integrated contains an abs() . This is a non-smooth function and inconsequence the solution suffers from the problems described here. The step size control of ODE45 must fail at the changes of the sign. To handle this, the step size is reduced until the discontinuity is covered by the rounding errors.
Better use an event function and restart the integration at the discontinuity.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by