Determine where lines intersect

21 次查看(过去 30 天)
Andreas
Andreas 2014-9-29
评论: Jan 2014-10-5
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?

回答(1 个)

Mischa Kim
Mischa Kim 2014-9-29
编辑:Mischa Kim 2014-9-29
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 个评论
Jan
Jan 2014-10-5
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by