Path: news.mathworks.com!not-for-mail
From: "Roland " <burgmann@gmx.de>
Newsgroups: comp.soft-sys.matlab
Subject: ode, tan, singularity?
Date: Thu, 8 Mar 2012 22:30:45 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <jjbbul$r7c$1@newscl01ah.mathworks.com>
Reply-To: "Roland " <burgmann@gmx.de>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1331245845 27884 172.30.248.38 (8 Mar 2012 22:30:45 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 8 Mar 2012 22:30:45 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1293762
Xref: news.mathworks.com comp.soft-sys.matlab:760411

I want to plot a curve with a constant curvature. this code works very well:

function curv()
data.beta_2=89*pi/180;
data.beta_1=20*pi/180;
data.z_2 = 0;
data.z_1 = 1;
opts = odeset('events',@(u,z) cross_z_z_min(u,z,data));
[u,z]=ode45(@(u,z) fun_dz_du(u,z,data),[0 inf],data.z_1,opts);
plot(u,z)
axis equal

function dz_du = fun_dz_du(u,z,data)
beta_2=data.beta_2;
beta_1=data.beta_1;
z_2 = data.z_2;
z_1 = data.z_1;
beta = beta_1 - (beta_1-beta_2)*(z-z_1)/(z_2-z_1);
dz_du = -tan(beta);

function [gstop,isterminal,direction]=cross_z_z_min(u,z,data)
gstop = z-data.z_2;
isterminal = 1;
direction = [];


whereas when I change beta_2 to 91 degree the ode solver hangs up. I guess its related to the singularity of the tan function at 90 degree, but I dont know how to overcome that problem. Any ideas?