?? cont.m
字號:
debug('npoints curve = %d\n', npoints);
string=sprintf('%.1f secs\n', etime(EndTime, StartTime));
set(MC.mainwindow.duration,'String',string);
set(status,'String','ready');
if ishandle(driver_window),delete(driver_window);end
%--< END OF CONTINUER >--
%-----------------------------------
%
% Command line parser
%
%-----------------------------------
function [curve, x, v, options] = ParseCommandLine(curve, x0, varargin)
% if nargin < 2 | ~isstr(curve) | isempty(x0)
if nargin < 2 | isempty(x0)
error('error in parameters, see help');
end
x = x0;
v = [];
options = contset;
if nargin > 2
v = varargin{1};
if nargin > 3
options = contmrg(options,varargin{2});
end
end
%--< END OF CMDL PARSER >--
%-------------------------------------
%
% Start point Corrector
%
%-------------------------------------
function [x,v] = CorrectStartPoint(x0, v0)
global cds
x = [];
v = [];
% no tangent vector given, cycle through base-vectors
i = 1;
%n = cds.ndim/2;
if ~isempty(v0)
[x,v] = newtcorr(x0,v0);
end
v0 = zeros(cds.ndim,1);
while isempty(x) & i<=cds.ndim
% fprintf('%d/%d \r', i, cds.ndim);
v0(i) = 1;
DefaultProcessor(x0,v0);
[x,v] = newtcorr(x0, v0);
v0(i) = 0;
i=i+1;
end
%fprintf('\n');
% if ~isempty(x)
% debug('Start point corrected with base vector e(%d)\n', i);
%end
%--< END OF ST PNT CORRECTOR >--
%------------------------------------------
%
% Evaluate testfunctions
%
%------------------------------------------
function [out,failed] = EvalTestFunc(id,x,v)
global cds
if id == 0
% WM: evaluate all testfunctions at once
[out,failed] = feval(cds.curve_testf, 1:cds.nTest, x, v);
else
[out,failed] = feval(cds.curve_testf, id, x, v);
end
%--< END OF TESTF EVAL >--
%------------------------------------------------------------
%
% Locate singularity xs between x1 and x2
% First locating zeros of testfunctions, then glue them
%
%------------------------------------------------------------
function [xs,vs] = LocateSingularity(si)
global cds
% zero locations of testf i is stored in testzero(:,i)
% if 1 zero/tf check if nonzero/tf _is_ nonzero at that point
% if more zero/tf then glue, nonzero/tf is kind of a problem because can always be found
idx = find( cds.S(si,:)==0 );
nzs = find( cds.S(si,:)==1 );
len = length(idx);
lnz = length(nzs);
trg = 0;
cnt = 0;
switch len
case 0
% Oops, we have detected a singularity without a vanishing testfunction
error('Internal error: trying to locate a non-detected singularity');
case 1
% check all nonzero/tf
xs = cds.testzero(:,idx);
vs = cds.testvzero(:,idx);
otherwise
tz = zeros(cds.ndim,len);
vz = zeros(cds.ndim,len);
nm = zeros(1,len);
for i=1:len
tz(:,i) = cds.testzero(:,idx(i));
vz(:,i) = cds.testvzero(:,idx(i));
nm(i) = norm(tz(:,i));
end
if max(nm)-min(nm) < cds.options.FunTolerance
xs = mean(tz',1)';
vs = mean(vz',1)';
else
xs = [];
vs = [];
return;
end
end
if lnz == 0, return; end
% checking non zeros
DefaultProcessor(xs,vs);
tval = EvalTestFunc(nzs, xs, vs);
if any(abs(tval(nzs)) <= cds.options.TestTolerance)
xs = [];
vs = [];
end
%debug('nz of tf %d = %f\n', nzs(ti), tv);
%------------------------------------------------
%
% Sorts [xs,vs] and sing with x1 starting point
% xs contains x_singular, vs v_singular
% sing contains their id's
% Sort criterion: dist(x1,x)
%
%------------------------------------------------
function [xs,vs,sing] = xssort(x1, xs, vs, sing)
% WM: Matlab has a sort function, beter use it...
len = size(xs,2);
if len > 1
xo = x1(:,ones(1,len));
[dummy,i] = sortrows([xs-xo]');
xs = xs(:,i);
vs = vs(:,i);
sing = sing(:,i);
end
%--< END OF XSSORT >--
%----------------------------
%
% DefaultProcessor
%
%----------------------------
function [failed,f,s] = DefaultProcessor(x,v,s)
global cds
% WM: this now actually calls the default processor,
% either with or without a singular point structure
if nargin > 2
[failed,f,s] = feval(cds.curve_defaultprocessor, x, v, s);
else
[failed,f] = feval(cds.curve_defaultprocessor, x, v);
end
%--< END OF DEFAULTPROCESSOR >--
function checkstupid(x)
[r,c] = size(x);
if c ~= 1
error('coordinates are column vectors, not row vectors or tensors or whatever');
end
%----------------------------------------------
function [x,v,i] = LocateTestFunction(id,x1,v1,x2,v2)
% default locator: bisection
global cds
%debug('locating tfz %d\n', id);
% WM: eliminated found variable
i = 1;
t1 = EvalTestFunc(id,x1,v1);
t2 = EvalTestFunc(id,x2,v2);
tmax = 10*max(abs(t1(id)),abs(t2(id)));
p = 1;
try
while i<=cds.options.MaxTestIters
% WM: make educated guess of where the zero point might be
if tmax < Inf
r = abs(t1(id)/(t1(id)-t2(id)))^p;
else
r=0.5;
end
% r = 0.5; % -> 'normal' way
x3 = x1 + r*(x2-x1);
v3 = v1 + r*(v2-v1);
[x,v] = newtcorr(x3,v3);
if isempty(x)
x = x3;
v = v3;
end
DefaultProcessor(x,v);
tval = EvalTestFunc(id,x,v);
dist1 = norm(x-x1);
dist2 = norm(x-x2);
if abs(tval(id)) > tmax
% fprintf('testfunction behaving badly.\n');
x = [];
break;
end
if abs(tval(id)) <= cds.options.TestTolerance & min(dist1,dist2) < cds.options.VarTolerance
break;
% elseif sign(tval(id))~=sign(cds.testvals(cds.atv,id))
% change by WG
elseif sign(tval(id))==sign(t2(id))
x2 = x;
v2 = v;
t2 = tval;
p = 1.02;
else
x1 = x;
v1 = v;
t1 = tval;
p = 0.98;
end
i = i+1;
x=[];
end
catch
x = [];
v = [];
i = cds.options.MaxTestIters;
end
%--< END OF locatetestfunction>--
%---------------------------------------------
%----------------------------------------------
%
%LocateUserFunction(id,x1,v1,x2,v2)
%
%----------------------------------------------
function [x,v,i] = LocateUserFunction(userinf,id,x1,v1,x2,v2)
% default locator: bisection
global cds
%debug('locating tfz %d\n', id);
% WM: eliminated found variable
i = 1;
t1 = feval(cds.curve_userf, userinf, id, x1, v1);
t2 = feval(cds.curve_userf, userinf, id, x2, v2);
tmax = 10*max(abs(t1),abs(t2));
p = 1;
try
while i<=cds.options.MaxTestIters
if tmax < Inf
% WM: make educated guess of where the zero point might be
r = abs(t1/(t1-t2))^p;
else
r=0.5
end
% r = 0.5; % -> 'normal' way
x3 = x1 + r*(x2-x1);
v3 = v1 + r*(v2-v1);
[x,v] = newtcorr(x3,v3);
if isempty(x)
x = x3;
v = v3;
end
DefaultProcessor(x,v);
tval=feval(cds.curve_userf,userinf,id,x,v);
dist1 = norm(x-x1);
dist2 = norm(x-x2);
if abs(tval) > tmax
% fprintf('testfunction behaving badly.\n');
x = [];
break;
end
if abs(tval) <= cds.options.TestTolerance & min(dist1,dist2) < cds.options.VarTolerance
% if abs(tval) < cds.options.TestTolerance & dist < cds.options.VarTolerance
break;
% elseif sign(tval(id))~=sign(cds.testvals(cds.atv,id))
% change by WG
elseif sign(tval)==sign(t2)
x2 = x;
v2 = v;
t2 = tval;
p = 1.02;
else
x1 = x;
v1 = v;
t1 = tval;
p = 0.98;
end
i = i+1;
x=[];
end
catch
end
%--< END OF locateuserfunction>--
%SD:actual continuer code
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -