Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

function output = dfield8(action,input1,input2,input3) % dfield8 is an interactive tool for studying single first order % differential equations. When dfield8 is executed, a dfield8 Setup

function output = dfield8(action,input1,input2,input3) % dfield8 is an interactive tool for studying single first order % differential equations. When dfield8 is executed, a dfield8 Setup % window is opened. The user may enter the differential % equation and specify a display window using the interactive % controls in the Setup window. % % When the Proceed button is pressed on the Setup window, the DF % Display window is opened. At first this window displays a % direction line field for the differential equation. When the % mouse button is depressed in the dfield8 Display window, the % solution to the differential equation with that initial % condition is calculated and plotted. % % Other options are available in the Options menu. These are % fairly self explanatory. The Settings option allows the user % to change several parameters. Included here are the % possibilities of using a vector field instead of the default % line field, and of changing the number of field points computed % and displayed. % Copywright (c) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003 % John C. Polking Rice University % Last modified: April 2, 2003 startstr = 'dfield8'; if nargin < 1 action ='initialize'; end % disp(action) if strcmp(action,'initialize') % First we make sure that there is no other copy of dfield8 % running, since this causes problems. dfh = findobj('tag','dfield8'); if ~isempty(dfh); qstring = {'There are some open dfield8 figures (perhaps invisible). ';... 'What do you want to do?'}; tstring = 'Only one copy of dfield8 can be open at one time.'; b1str = 'Restart dfield8.'; b2str = 'Just close those figures.'; b3str = 'Do nothing.'; answer = questdlg(qstring,tstring,b1str,b2str,b3str,b1str); if strcmp(answer,b1str) delete(dfh); eval(startstr);return elseif strcmp(answer,b2str) delete(dfh);return else return end end % if ~isempty(dfh); % Make sure tempdir is on the MATLABPATH. We want to be sure that we % return the path to its current position when we exit. p = path; tmpdir = tempdir; ll = length(tmpdir); tmpdir = tmpdir(1:ll1); ud.remtd = 0; if isempty(findstr(tmpdir,p)) ud.remtd = 1; addpath(tempdir) end % Next we look for old files created by dfield8. oldfiles = dir('dftp*.m'); kk = zeros(0,1); for k = 1:length(oldfiles) fn = oldfiles(k).name; fid = fopen(fn,'r'); if fid ~= 1 ll = fgetl(fid); ll = fgetl(fid); ll = fgetl(fid); fclose(fid); if strcmp(ll,'%% Created by dfield8') delete(fn) else kk = [kk;k]; end end end oldfiles = dir([tempdir,'dftp*.m']); for k = 1:length(oldfiles) fn = [tempdir,oldfiles(k).name]; fid = fopen(fn,'r'); if fid ~= 1 ll = fgetl(fid); ll = fgetl(fid); ll = fgetl(fid); fclose(fid); if isempty(findstr('%% Created by DF',ll)) kk = [kk;k]; else delete(fn) end end end if ~isempty(kk) fprintf('The following files\ '); for j = 1:length(kk) fn = [tempdir,oldfiles(kk(j)).name]; fn = strrep(fn,'\\','\\\\'); fprintf([' ',fn,'\ ']); end fprintf('may have been created by an older version of DFIELD.\ '); fprintf('If so they should be deleted.\ \ '); end style = 'white'; dfdir = pwd; ssize = get(0,'defaultaxesfontsize'); npts = 20; solver = 'DormandPrince'; solvhandle = @dfdp45; if exist('dfstart','file') H = dfstart; if ~isempty(H) if isfield(H,'style') style = H.style; end if isfield(H,'size') ssize = H.size; end if isfield(H,'npts') npts = H.npts; end if isfield(H,'dfdir') dfdir = H.dfdir; end if isfield(H,'solver') solver = H.solver; switch solver case 'DormandPrince' solvhandle = @dfdp45; case 'Euler' solvhandle = @dfeul; case 'RungeKutta 2' solvhandle = @dfrk2; case 'RungeKutta 4' solvhandle = @dfrk4; otherwise error('Undefined solver.'); end end end end if get(0,'screendepth') == 1 style = 'bw'; end ud.ssize = ssize; ud.dfdir = dfdir; comp = computer; if strcmp(comp,'PCWIN') ud.fontsize = 0.8*ud.ssize; else ud.fontsize = ud.ssize; end system.name = 'default equation'; system.xname = 'x'; system.tname = 't'; system.der = ' x^2 t'; system.wind = [2 10 4 4]; system.pname = {}; system.pval = {}; system(2).name = 'logistic equation'; system(2).xname = 'P'; system(2).tname = 't'; system(2).der = ' r*P*(1 P/K)'; system(2).wind = [0 20 0 15]; system(2).pname = {'r','K','',''}; system(2).pval = {'0.75','10','',''}; system(3).name = 'RC circuit'; system(3).xname = 'V_c'; system(3).tname = 't'; system(3).der = '(A*cos(\\omega*t) V_c)/(R*C)'; system(3).wind = [0 10 5 5]; system(3).pname = {'A' '\\omega' 'R' 'C'}; system(3).pval = {'5' '3' '0.5' '2'}; system(4).name = 'RL circuit'; system(4).xname = 'I'; system(4).tname = 't'; system(4).der = '(A*cos(\\omega*t) R*I)/L'; system(4).wind = [0 10 5 5]; system(4).pname = {'A' '\\omega' 'R' 'L'}; system(4).pval = {'5' '3' '3' '2'}; ud.c = system(1); % Changed values. ud.o = system(1); % Original values. ud.fieldtype = 'lines'; ud.npts = npts; ud.style = style; ud.settings.magn = 1.25; ud.settings.refine = 4; ud.settings.tol = 1e6; ud.settings.solver = solver; ud.settings.solvhandle = solvhandle; ud.settings.stepsize = 0.1; ud.settings.hmax = 0; ud.settings.speed = 100; ud.system = system; switch style case 'black' color.temp = [1 0 0]; % red for temporary orbits color.orb = [1 1 0]; % yellow for orbits color.arrows = .5*[1 1 1]; % gray for arrows color.pline = [1 1 1]; color.level = [1,.5,.5]; case 'white' color.temp = [1 0 0]; % red for temporary orbits color.orb = [0 0 1]; % blue for orbits color.arrows = .7*[1 1 1]; % gray for arrows color.pline = [0 0 0]; color.level = 0.8*[.9,.5,.8]; case 'test' color.temp = [1 0 0]; % red for temporary orbits color.orb = [0 0 1]; % blue for orbits color.arrows = .7*[1 1 1]; % gray for arrows color.pline = [0 0 0]; color.level = [1,.5,.5]; case 'display' color.temp = [1 0 0]; % red for temporary orbits color.orb = [0 0 1]; % blue for orbits color.arrows = .4*[1 1 1]; % gray for arrows color.pline = [0 0 0]; color.level = [255 150 10]/255;% 0.8*[.9,.5,.8]; case 'bw' color.temp = [1 1 1]; % white for everything color.orb = [1 1 1]; color.arrows = [1 1 1]; color.pline = [1 1 1]; color.level = [1,1,1]; end ud.color = color; dfset = figure('name','dfield8 Setup','numb','off',... 'tag','dfield8','visible','off',... 'user',ud); dfield8('figdefault',dfset); frame(1) = uicontrol('style','frame','visible','off'); eq(1)=uicontrol('style','text',... 'horizon','center',... 'string','The differential equation.','visible','off'); ext = get(eq(1),'extent'); rr=ext(4)/10; texth =ext(4)+4; % Height of text boxes. varw = 40*rr; % Length of variable boxes. equalw =13*rr; % Length of equals.(30) eqlength = 230*rr; % Length of right hand sides of equations. winstrlen = 120*rr;% Length of string boxes in display frame. left = 1; % Left margin of the frames. frsep = 1; % Separation between frames. separation = texth;% Separation between boxes. disfrw = varw+equalw+eqlength+10; dfigwidth =2*left + disfrw; % Width of the figure. dfigurebot = 60; % Bottom of the figure. buttw = dfigwidth/3; qwind = [0,frsep,buttw,separation]; % Quit button rwind = [buttw,frsep,buttw,separation]; % Revert " pwind = [2*buttw,frsep,buttw,separation]; % Proceed " disfrbot = 2*frsep + separation; % Display frame. disfrht = 3*separation + 10; disfrwind = [left, disfrbot, disfrw, disfrht]; pfrbot = disfrbot + disfrht + frsep; pfrw = disfrw; pfrht = 2*separation + 10; pfrwind = [left, pfrbot, pfrw, pfrht]; defrbot = pfrbot + pfrht + frsep; % Equation frame. defrw = pfrw; defrht = 3*separation + 15; defrwind = [left, defrbot, defrw, defrht]; dfigureheight = defrbot + defrht +frsep; % Height of the figure. set(dfset,'pos',[30 dfigurebot dfigwidth dfigureheight]); set(frame(1),'pos',defrwind); xname=[ 'ud = get(gcf,''user'');'... 'Xname=get(ud.h.xname,''string'');'... 'set(ud.h.twind(3),''string'','... '[''The minimum value of '',Xname,'' = '']);'... 'set(ud.h.twind(4),''string'','... '[''The maximum value of '',Xname,'' = '']);'... 'ud.c.xname = Xname;'... 'ud.flag = 0;'... 'set(gcf,''user'',ud);']; tname=[ 'ud = get(gcf,''user'');'... 'Tname=get(ud.h.tname,''string'');'... 'set(ud.h.twind(1),''string'','... '[''The minimum value of '',Tname,'' = '']);'... 'set(ud.h.twind(2),''string'','... '[''The maximum value of '',Tname,'' = '']);'... 'ud.c.tname = Tname;'... 'ud.flag = 0;'... 'set(gcf,''user'',ud);']; der =[ 'ud = get(gcf,''user'');'... 'ud.c.der = get(ud.h.der,''string'');'... 'ud.flag = 0;'... 'set(gcf,''user'',ud);']; equationbot = defrbot + 5; eqlabelbot = equationbot + 2*separation; derbot = equationbot + separation + 5; % Bottom of equation. tbot = equationbot; % Bottom of ind. var. lablen =200*rr; eqlableft = (dfigwidthlablen)/2; eqleft = left + 5; fudge = 0.15*separation; set(eq(1),'pos',[eqlableft eqlabelbot lablen texth]); tcolor = get(gcf,'defaultuicontrolbackgroundcolor'); ecolor = 'w'; ud.h.xname=uicontrol('pos',[eqleft, derbot, varw, texth],... 'style','edit',... 'horizon','right',... 'string',ud.o.xname,... 'call',xname,... 'visible','off',... 'backgroundcolor',ecolor); eq(2) = uicontrol('style','text',... 'pos',[eqleft+varw derbotfudge equalw texth],... 'horizon','center','string',''' = ','visible','off',... 'backgroundcolor',tcolor); ud.h.der=uicontrol('pos',[eqleft+varw+equalw derbot eqlength texth],... 'string',ud.o.der,... 'horizon','left','style','edit',... 'call',der,'visible','off','backgroundcolor',ecolor); eq(3) = uicontrol('style','text',... 'horizon','right',... 'string','The independent variable is ',... 'visible','off','backgroundcolor',tcolor); ext = get(eq(3),'extent'); tnw = ext(3)+10; tvarl = eqleft + tnw; set(eq(3),'pos',[eqleft,tbotfudge,tnw,texth]); ud.h.tname = uicontrol('pos',[tvarl tbot varw texth],... 'style','edit',... 'horizon','left',... 'string',ud.o.tname,... 'call',tname,... 'visible','off',... 'backgroundcolor',ecolor); pframe = uicontrol('style','frame','pos',pfrwind,'visible','on') ; pncall = [ '[h,fig] = gcbo;'... 'ud = get(fig,''user'');'... 'num = get(h,''user'');'... 'ud.c.pname{num} = get(ud.h.pname(num),''string'');'... 'ud.flag = 0;'... 'set(gcf,''user'',ud);']; pvcall = [ '[h,fig] = gcbo;'... 'ud = get(fig,''user'');'... 'num = get(h,''user'');'... 'ud.c.pval{num} = get(ud.h.pval(num),''string'');'... 'ud.flag = 0;'... 'set(gcf,''user'',ud);']; pnamew = 30*rr; peqw = 8*rr; pbot1 = pfrbot + 5; pbot2 = pbot1 +separation; pbot(1) = pbot2; pbot(2) = pbot1; paratit=uicontrol('style','text',... 'horizon','center',... 'string', {'Parameters';'&';'expressions:'},... 'visible','off','backgroundcolor',tcolor); ext = get(paratit,'extent'); paratitw = ext(3); pos = [eqleft pbot(2) paratitw 2*texth]; set(paratit,'pos',pos); psep = 20; pvalw = (dfigwidth 2*eqleft paratitw)/2 psep pnamew peqw; pval = ud.c.pval; pname = ud.c.pname; for jj = 1:2 for kk = 1:2 pleft = eqleft + paratitw +psep +(kk 1)*(pnamew+peqw+pvalw+ psep); peqleft = pleft + pnamew; pvleft = peqleft + peqw; K = kk +2*(jj1); if K > length(pname) pname{K} = ''; end name = pname{K}; if K <= length(pval) value = pval{K}; else value = ''; end ud.h.pname(K) = uicontrol('style','edit',... 'pos',[pleft pbot(jj) pnamew texth],... 'horizon','right','string',name,... 'user',K,... 'call',pncall,... 'visible','off',... 'backgroundcolor','w'); equal(K) = uicontrol('style','text',... 'pos',[peqleft pbot(jj)fudge peqw texth],... 'horizon','center',... 'string','=',... 'visible','off'); ud.h.pval(K) = uicontrol('style','edit',... 'pos',[pvleft pbot(jj) pvalw texth],... 'string',value,... 'call',pvcall,... 'visible','off',... 'user',K,... 'backgroundcolor','w'); end end ud.c.pname = pname; ud.c.pval = pval; pbot = pbot + texth; frame(2) = uicontrol('style','frame','pos',disfrwind,'visible','of f'); w1 = [ 'ud = get(gcf,''user'');'... 'nnn = str2num(get(ud.h.wind(1),''string''));'... 'if isempty(nnn),',... ' set(ud.h.wind(1),''string'',''?'');',... ' nnn = NaN;',... 'end,',... 'ud.c.wind(1) = nnn;',... 'set(gcf,''user'',ud);']; w2 = [ 'ud = get(gcf,''user'');'... 'nnn = str2num(get(ud.h.wind(2),''string''));'... 'if isempty(nnn),',... ' set(ud.h.wind(2),''string'',''?'');',... ' nnn = NaN;',... 'end,',... 'ud.c.wind(2) = nnn;',... 'set(gcf,''user'',ud);']; w3 = [ 'ud = get(gcf,''user'');'... 'nnn = str2num(get(ud.h.wind(3),''string''));'... 'if isempty(nnn),',... ' set(ud.h.wind(3),''string'',''?'');',... ' nnn = NaN;',... 'end,',... 'ud.c.wind(3) = nnn;',... 'set(gcf,''user'',ud);']; w4 = [ 'ud = get(gcf,''user'');'... 'nnn = str2num(get(ud.h.wind(4),''string''));'... 'if isempty(nnn),',... ' set(ud.h.wind(4),''string'',''?'');',... ' nnn = NaN;',... 'end,',... 'ud.c.wind(4) = nnn;',... 'set(gcf,''user'',ud);']; winbot1 = disfrbot + disfrht 5 separation; winbot2 = winbot1 separation; winbot3 = winbot2 separation; windw = 40*rr; twindw = (disfrw 10)/2windw; twindl = eqleft + twindw + windw; dwind = uicontrol('style','text',... 'pos',[eqleft winbot1 disfrw10 texth],... 'horizon','center',... 'string','The display window.','visible','off',... 'backgroundcolor',tcolor); % ud.h.twind contains the handles to the text windows, and ud.h.wind % contains the handles to the edit windows. ud.h.twind(1) = uicontrol('style','text',... 'pos',[eqleft winbot2fudge twindw texth],... 'horizon','right',... 'string',['The minimum value of ',ud.o.tname,' = '],... 'visible','off','backgroundcolor',tcolor); ud.h.wind(1) = uicontrol('style','edit',... 'pos',[eqleft+twindw winbot2 windw texth],... 'string',num2str(ud.o.wind(1)),... 'call',w1,'visible','off',... 'backgroundcolor',ecolor); ud.h.twind(2) = uicontrol('style','text',... 'pos',[eqleft winbot3fudge twindw texth],... 'horizon','right',... 'string',['The maximum value of ',ud.o.tname,' = '],... 'visible','off','backgroundcolor',tcolor); ud.h.wind(2) = uicontrol('style','edit',... 'pos',[eqleft+twindw winbot3 windw texth],... 'string',num2str(ud.o.wind(2)),... 'call',w2,'visible','off',... 'backgroundcolor',ecolor); ud.h.twind(3)= uicontrol('style','text',... 'pos',[twindl winbot2fudge twindw texth],... 'horizon','right',... 'string',['The minimum value of ',ud.o.xname,' = '],... 'visible','off','backgroundcolor',tcolor); ud.h.wind(3) = uicontrol('style','edit',... 'pos',[twindl+twindw winbot2 windw texth],... 'string',num2str(ud.o.wind(3)),... 'call',w3,'visible','off',... 'backgroundcolor',ecolor); ud.h.twind(4) = uicontrol('style','text',... 'pos',[twindl winbot3fudge twindw texth],... 'horizon','right',... 'string',['The maximum value of ',ud.o.xname,' = '],... 'visible','off','backgroundcolor',tcolor); ud.h.wind(4) = uicontrol('style','edit',... 'pos',[twindl+twindw winbot3 windw texth],... 'string',num2str(ud.o.wind(4)),... 'call',w4,'visible','off',... 'backgroundcolor',ecolor); butt(1) = uicontrol('style','push',... 'pos',qwind,... 'string','Quit',... 'call','dfield8(''quit'')',... 'visible','off'); butt(2) = uicontrol('style','push',... 'pos',rwind,... 'string','Revert',... 'call','dfield8(''revert'')',... 'visible','off'); butt(3) = uicontrol('style','push',... 'pos',pwind,... 'string','Proceed',... 'call','dfield8(''proceed'')',... 'visible','off'); hhsetup = get(0,'showhiddenhandles'); set(0,'showhiddenhandles','on'); delgall = ['sud = get(gcf,''user'');',... 'mh = get(sud.h.gallery,''children'');',... 'add = findobj(sud.h.gallery,''tag'',''add system'');',... 'mh(find(mh == add)) = ;',... 'delete(mh);',... 'set(sud.h.gallery,''user'',);',... 'set(findobj(''tag'',''load default''),''enable'',''on'')']; mefile = findobj(dfset,'label','&File'); meedit = findobj(gcf,'label','&Edit'); metools = findobj(gcf,'label','&Tools'); meview = findobj(gcf,'label','&View'); meinsert = findobj(gcf,'label','&Insert'); delete([metools,meview,meinsert]); % File menu meexp = findobj(mefile,'label','&Export...'); meprev = findobj(mefile,'label','Print Pre&view...'); mepset = findobj(mefile,'label','Pa&ge Setup...'); set(get(mefile,'child'),'vis','off'); meload = uimenu(mefile,'label','Load an equation ...',... 'call','dfield8(''loadsyst'',''system'');',... 'pos',1); mesave = uimenu(mefile,'label','Save the current equation ...',... 'call','dfield8(''savesyst'',''system'');',... 'pos',2); meloadg = uimenu(mefile,'label','Load a gallery ...',... 'call','dfield8(''loadsyst'',''gallery'');',... 'separator','on','pos',3); mesaveg = uimenu(mefile,'label','Save a gallery ...',... 'call','dfield8(''savesyst'',''gallery'');',... 'tag','savegal','pos',4); medelg = uimenu(mefile,'label','Delete the current gallery',... 'call',delgall,'pos',5); melddg = uimenu(mefile,'label','Load the default gallery',... 'call','dfield8(''loadsyst'',''default'');',... 'enable','on',... 'tag','load default','pos',6); meproceed = uimenu(mefile,'label','Proceed','call',... 'dfield8(''proceed'')','separator','on',... 'accelerator','G','pos',7); merevert = uimenu(mefile,'label','Revert','call',... 'dfield8(''revert'')','separator','off','pos',8); set(mepset,'vis','on','pos',9); set(meprev,'vis','on','label','Page Pre&view...','pos',10); set(meexp,'vis','on','pos',11,'separator','off'); merestart = uimenu(mefile,'label','Restart dfield8','call',... 'dfield8(''restart'')','separator','on','pos',12); mequit = uimenu(mefile,'label','Quit dfield8','call',... 'dfield8(''quit'')','separator','on','pos',13); % Edit menu. set(get(meedit,'child'),'vis','off'); meclrf = uimenu(meedit,'label','Clear equations',... 'call',['ud = get(gcf,''user'');h = ud.h;',... 'set([h.xname,h.der,h.tname,h.der],''string'','''');'], ... 'accelerator','E'); pclear = [ 'ud = get(gcf,''user'');h = ud.h;',... 'set([h.pname,h.pval],''string'','''');',... 'ud.c.pname = {};',... 'ud.c.pval = {};',... 'set(gcf,''user'',ud);',... ]; meclrp = uimenu(meedit,'label','Clear parameters',... 'call',pclear,... 'accelerator','N'); meclrwind = uimenu(meedit,'label','Clear display window',... 'call',['ud = get(gcf,''user'');',... 'set(ud.h.wind,''string'','''');'],... 'accelerator','D'); allclear = [ 'ud = get(gcf,''user'');h = ud.h;',... 'set([h.xname,h.der,h.tname],''string'','''');',.. . 'set([h.pname,h.pval,h.wind],''string'','''');',.. . 'ud.c.pname = {};',... 'ud.c.pval = {};',... 'set(gcf,''user'',ud);',... ]; meclrall = uimenu(meedit,'label','Clear all',... 'call',allclear,... 'accelerator','A',... 'separator','on'); % Gallery menu. sysmenu = uimenu('label','Gallery','visible','off','pos',3); meadd = uimenu(sysmenu,'label','Add current equation to the gallery',... 'call','dfield8(''addgall'');','tag','add system'); sep = 'on'; for kk = 1:length(system) kkk = num2str(kk); if kk == 2, sep = 'off';end sysmen(kk) = uimenu(sysmenu,'label',system(kk).name,... 'call', ['dfield8(''system'',',kkk,')'],... 'separator',sep,'visible','on'); end set(sysmenu,'user',system); ud.h.gallery = sysmenu; set(0,'showhiddenhandles',hhsetup); ud.flag = 0; % Record the handles in the User Data of the Set Up figure. set(dfset,'user',ud); hhhh = findobj(dfset,'type','uicontrol'); set(hhhh,'units','normal') set(dfset,'visible','on','resize','on'); set(get(dfset,'children'),'visible','on'); elseif strcmp(action,'revert') ud = get(gcf,'user'); ud.c = ud.o; syst = ud.o; xname = syst.xname; tname = syst.tname; set(ud.h.xname,'string',xname); set(ud.h.tname,'string',tname); set(ud.h.der,'string',syst.der); set(ud.h.twind(1),'string',['The minimum value of ',tname,' = ']); set(ud.h.twind(2),'string',['The maximum value of ',tname,' = ']); set(ud.h.twind(3),'string',['The minimum value of ',xname,' = ']); set(ud.h.twind(4),'string',['The maximum value of ',xname,' = ']); for kk = 1:4 set(ud.h.wind(kk),'string',num2str(syst.wind(kk))); end for kk = 1:4 if kk <= length(syst.pname) name = syst.pname{kk}; else name = ''; end if kk <= length(syst.pval) value = syst.pval{kk}; else value = ''; end set(ud.h.pname(kk),'string',name); set(ud.h.pval(kk),'string',value); end set(gcf,'user',ud); elseif strcmp(action,'proceed') % Proceed connects Setup with the Display window. dfset = gcf; sud = get(dfset,'user'); sud.o = sud.c; set(dfset,'user',sud); % Some error checking that has to be done no matter what. WINvect = sud.c.wind; if any(isnan(WINvect)) errmsg = ['One of the entries defining the display window ',... 'is not a number.']; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); return end xstr = sud.c.xname; if isempty(xstr) errmsg = 'The dependent variable needs a name.'; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); return end tstr = sud.c.tname; if isempty(tstr) errmsg = 'The independent variable needs a name.'; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); return end if WINvect(2)<= WINvect(1) errmsg = ['The minimum value of ', tstr,... ' must be smaller than the maximum value.']; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); return end if WINvect(4)<= WINvect(3) errmsg = ['The minimum value of ', xstr,... ' must be smaller than the maximum value.']; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); return end % sud.flag = 0 if this is the first time through for this equation, % sud.flag = 1 if only the window dimensions have been changed. % If sud.flag == 1 we only have to update things. if (sud.flag == 1) dfdisp = findobj('name','dfield8 Display'); dud = get(dfdisp,'user'); aud = get(dud.axes,'user'); tstr = get(get(dud.axes,'title'),'string'); wind = sud.c.wind(:); hmax = dud.settings.hmax; if (~all(wind == dud.syst.wind(:))) dwind = [wind(1); wind(3); wind(2); wind(4)]; DY = [wind(2)wind(1); wind(4)wind(3)]; hmax = min(hmax,DY(1)/4); aud.DY = DY; aud.cwind = wind dud.settings.magn*[DY(1); DY(1);DY(2);DY(2)]; set(dud.axes,'user',aud); end dud.syst = sud.c; dud.settings = sud.settings; dud.settings.hmax = hmax; set(dfdisp,'user',dud); dfield8('dirfield',dfdisp); else sud.flag = 1; set(dfset,'user',sud); Arrflag = sud.fieldtype; NumbFPts = sud.npts; Xname = sud.c.xname; Tname = sud.c.tname; derivstr = sud.c.der; pname = sud.c.pname; parav = get(sud.h.pval,'string'); % First remove the blanks. derivstr(find(abs(derivstr)==32))=; for kk = 1:4 paraval = parav{kk}; if ~isempty(paraval) paraval(find(abs(paraval)==32))=; parav{kk} = paraval; end end % Next remove the periods inserted by users attempting to make the % function array smart. l=length(derivstr); for ( k = fliplr(findstr('.',derivstr))) if (find('*/^' == derivstr(k+1))) derivstr = [derivstr(1:k1), derivstr(k+1:l)]; end l=l1; end for kk = 1:4 paraval = parav{kk}; l=length(paraval); for ( k = fliplr(findstr('.',paraval))) if (find('*/^' == paraval(k+1))) paraval = [paraval(1:k1), paraval(k+1:l)]; end l=l1; end parav{kk} = paraval; end % Build strings for the title. txderstr = derivstr; kxder = find(abs(txderstr)==42); % Get rid of *s txderstr(kxder)=' '*ones(size(kxder)); txderstr = strrep(txderstr,'',' '); % Extra spaces txderstr = strrep(txderstr,'+',' + '); if (abs(txderstr(1)) == 32) % Get rid of starting space txderstr = txderstr(2:length(txderstr)); end tstr = [Xname,' '' = ', txderstr]; pstring = cell(4,1); pstring{1} = ''; pstring{2} = ''; pstring{3} = ''; pstring{4} = ''; for kk = 1:4 if ~isempty(parav{kk}); tp1str = parav{kk}; kxder = find(abs(tp1str)==42); % Get rid of *s tp1str(kxder)=' '*ones(size(kxder)); tp1str = strrep(tp1str,'',' '); % Extra spaces tp1str = strrep(tp1str,'+',' + '); if (abs(tp1str(1)) == 32) % Get rid of starting space tp1str = tp1str(2:length(tp1str)); end pstring{kk} = [pname{kk},' = ', tp1str]; end end % Get ready to do some error trapping. SS = warning; warning off XxXxXx = WINvect(1) + rand*(WINvect(2) WINvect(1)); TtTtTt = WINvect(3) + rand*(WINvect(4) WINvect(3)); err = 0; % Now we remove the backslashes (\\) used to get Greek into the % labels. txname = Xname; ttname = Tname; derivstr(find(abs(derivstr)==92))=; Xname(find(abs(Xname)==92))=; Tname(find(abs(Tname)==92))=; eval([Xname,'=XxXxXx;'],'err = 1;'); if err errmsg = ['"',xstr, '" is not a valid variable name in MATLAB.']; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); warning(SS) return end err = 0; eval([Tname,'=TtTtTt;'],'err = 1;'); if err errmsg = ['"',tstr, '" is not a valid variable name in MATLAB.']; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); warning(SS) return end % Replace the parameters/expressions with their values. pflag = zeros(1,4); perr = ; pnameh = sud.h.pname; pvalh = sud.h.pval; for kk = 1:4; pn = char(get(pnameh(kk),'string')); pn(find(abs(pn)==92))=; pv = char(get(pvalh(kk),'string')); if ~isempty(pn) if isempty(pv) perr = pvalh(kk); else if isempty(str2num(pv)) % This is an expression. tpv = pv; tpv(find(abs(tpv)==92))=; err = 0; pval = ''; eval(['pval = ',tpv,';'],'err=1;'); %pval; if (err | isempty(pval)) errmsg = ['The expression for ',pn,' is not valid.']; fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); warning(SS) return end end xderivstr = dfield8('paraeval',pn,pv,derivstr); if ~strcmp(xderivstr,derivstr) pflag(kk) = 1; derivstr = xderivstr; end end end end % We have to make the derivative strings array smart. l = length(derivstr); for (k=fliplr(find((derivstr=='^')| (derivstr=='*')|(derivstr=='/')))) derivstr = [derivstr(1:k1) '.' derivstr(k:l)]; l = l+1; end % Some more error trapping. eval(['res = ',derivstr, ';'],'err = 1;'); if err | isempty(res) if isempty(perr) errmsg = ['The differential equation ',... 'is not entered correctly.']; else errstr1 = 'The differential equation does not evaluate correctly.'; errstr2 = 'At least one of the parameter values is not a number.'; errmsg = str2mat(errstr1,errstr2); set(perr,'string','?'); end fprintf('\\a') errordlg(errmsg,'dfield8 error','on'); dfield8('restart'); warning(SS); return end warning(SS); % Build a new derivative mfile. tee = clock; tee = ceil(tee(6)*100); dfcn=['dftp',num2str(tee)]; fcnstr = ['function YYyYypr = ',dfcn,'(TtTt,YyYy)\ \ ']; commstr = '%%%% Created by dfield8\ \ '; varstr = [Xname,' = YyYy;', Tname,' = TtTt;\ \ ']; lenstr = ['l = length(YyYy);\ ']; derstr1 = ['YYyYypr = ', derivstr,';\ ']; derstr2 = ['if (length(YYyYypr) < l) YYyYypr = YYyYypr*ones(1,l);end\ ']; dff = fopen([tempdir,dfcn,'.m'],'w'); fprintf(dff,fcnstr); fprintf(dff,commstr); fprintf(dff,varstr); fprintf(dff,lenstr); fprintf(dff,derstr1); fprintf(dff,derstr2); fclose(dff); % Find dfield8 Display if it exists. % If dfield8 Display exists, update it. If it does not build it. dfdisp = findobj('name','dfield8 Display'); if (~isempty(dfdisp)) figure(dfdisp); dud = get(dfdisp,'user'); dud.syst = sud.c; dud.settings = sud.settings; dfcnn = dud.function; if exist(dfcnn) == 2 delete([tempdir,dfcnn,'.m']) end else dfdisp = figure('name','dfield8 Display',... 'numb','off','interrupt','on',... 'visible','off','tag','dfield8'); dfield8('figdefault',dfdisp); dud = get(dfdisp,'user'); dud.syst = sud.c; dud.settings = sud.settings; fs = dud.fontsize; ssize = dud.ssize; r = ssize/10; dfaxw = 437*1.2; % Default axes width dfaxh = 315*1.2; % Default axes height dfaxl = 45*1.2; % Default axes left buttw = 40*1.2; % Default button width uni = get(0,'units'); set(0,'units','pixels'); ss = get(0,'screensize'); style = sud.style; set(0,'units',uni); nframeh = 70; % Default notice frame height dfaxb = 4+nframeh+35; titleh = 30; bottomedge = 38; dfdh = dfaxh + nframeh + titleh + bottomedge; sw = ss(3);sh = ss(4); bottom = 20; if r*dfdh > sh bottom 35; r = (shbottom35)/dfdh; fs = 10*r; lw = 0.5*r; set(gcf,'defaultaxesfontsize',fs,'defaultaxeslinewidth' ,lw); set(gcf,'defaulttextfontsize',fs); set(gcf,'defaultlinelinewidth',lw); set(gcf,'defaultuicontrolfontsize',fs*0.9); end % Set up the bulletin window. nframe = uicontrol('style','frame','visible','on'); nstr = {'More';'than';'five';'lines';'of text'}; dud.notice = uicontrol('style','text',... 'horiz','left',... 'string',nstr,'visible','on'); ext = get(dud.notice,'extent'); nframeh = ext(4)+2; titleh = r*titleh; dfaxl = r*dfaxl; buttw = r*buttw; butth = fs+20*r; dfaxw = r*dfaxw; dfaxh = r*dfaxh; dfaxb = nframeh+r*bottomedge; buttl = dfaxl + dfaxw + 5; buttsep = (dfaxh butth)/2; % Set up the coordinate display cstr = '(0.9999, 0,9999)'; dud.ccwind = uicontrol('style','text',... 'horiz','left',... 'string',cstr,... 'visible','on'); cext = get(dud.ccwind,'extent'); ccwindtxt = uicontrol('style','text',... 'horiz','left',... 'string','Cursor position: ',... 'visible','on'); cwh = cext(4); cww = cext(3); % Set up the plot axes. dud.axes = axes('units','pix',... 'position',[dfaxl,dfaxb,dfaxw,dfaxh],... 'next','add',... 'box','on',... 'interrupt','on',... 'xgrid','on',... 'ygrid','on',... 'drawmode','fast',... 'visible','off',... 'tag','display axes'); % Finish the positions. dfdw = buttl + buttw +5; dfdh = dfaxb+dfaxh+titleh; set(nframe,'pos',[10,1,dfdw20,nframeh]); set(dud.notice,'pos',[15,1,dfdw30,nframeh2],... 'string',{' ';' ';' ';' ';' '}); ctext = get(ccwindtxt,'extent'); cc1pos = [dfaxl,2+nframeh,ctext(3),cwh]; cc2pos = [dfaxl+ctext(3),2+nframeh,cww,cwh]; set(ccwindtxt,'pos',cc1pos); set(dud.ccwind,'pos',cc2pos,... 'string',''); dfdleft = max((swdfdw)/2,swdfdw60); dfdbot = sh dfdh 70; dfdpos = [dfdleft,dfdbot,dfdw,dfdh]; set(dfdisp,'resize','on'); set(dfdisp,'pos',dfdpos); Arrflag = sud.fieldtype; % Set up the buttons and the menu. stopstr = 'aud = get(gca,''user'');aud.stop = 4;set(gca,''user'',aud);'; dbutt(1) = uicontrol('style','push',... 'pos', [buttl,dfaxb+2*buttsep,buttw,butth],... 'string','Stop',... 'call',stopstr,... 'vis','off',... 'tag','stop'); dbutt(2) = uicontrol('style','push',... 'pos',[buttl,dfaxb,buttw,butth],... 'string','Quit',... 'call','dfield8(''quit'')',... 'visible','off'); dbutt(3) = uicontrol('style','push',... 'pos', [buttl,dfaxb+buttsep,buttw,butth],... 'string','Print',... 'call','dfield8(''print'')',... 'visible','off'); dud.butt = dbutt; hhsetup = get(0,'showhiddenhandles'); set(0,'showhiddenhandles','on'); % File menu fmenu = findobj(gcf,'label','&File'); delete(findobj(fmenu,'label','&New Figure')); delete(findobj(fmenu,'label','&Open...')); delete(findobj(fmenu,'label','&Close')); set(findobj(fmenu,'label','&Save'),... 'separator','off',... 'pos',1); set(findobj(fmenu,'label','Save &As...'),... 'pos',2); delete(findobj(fmenu,'label','Pre&ferences...')); set(findobj(fmenu,'label','&Export...'),... 'pos',3); set(findobj(fmenu,'label','Pa&ge Setup...'),'pos',4,... 'separator','on'); set(findobj(fmenu,'label','Print Pre&view...'),'pos',5); set(findobj(fmenu,'label','Print Set&up...'),'pos',6); set(findobj(fmenu,'label','&Print...'),'pos',7); merestart = uimenu(fmenu,'label','Restart dfield8','call',... 'dfield8(''restart'')','separator','on','pos',8); mequit = uimenu(fmenu,'label','Quit dfield8',... 'call','dfield8(''quit'')','separator','o n'); % Tools menu tmenu = findobj(gcf,'label','&Tools'); delete(tmenu); % Insert menu imenu = findobj(gcf,'label','&Insert'); inschild = get(imenu,'child'); legitem = findobj(inschild,'label','&Legend'); colitem = findobj(inschild,'label','&Colorbar'); delete([legitem,colitem]); % Edit menu emenu = findobj(gcf,'label','&Edit'); menu(2) = uimenu(emenu,'label','Zoom in.',... 'call','dfield8(''zoomin'')',... 'pos',1); zbmenu = uimenu(emenu,'label','Zoom back.',... 'call','dfield8(''zoomback'')',... 'enable','off',... 'tag','zbmenu',... 'pos',2); metext = uimenu(emenu,'label','Enter text on the Display Window.',... 'call','dfield8(''text'')',... 'separator','on',... 'pos',3); medel = uimenu(emenu,'label','Delete a graphics object.',... 'call','dfield8(''delete'')',... 'visible','on',... 'pos',4); medall = uimenu(emenu,'label','Erase all solutions.',... 'call','dfield8(''dallsol'')',... 'separator','off',... 'pos',5); medalllev = uimenu(emenu,'label','Erase all level curves.',... 'call','dfield8(''dalllev'')',... 'separator','off',... 'pos',6); medall = uimenu(emenu,'label','Erase all graphics objects.',... 'call','dfield8(''dall'')',... 'separator','off',... 'pos',7); set(findobj(emenu,'label','&Undo'),'separator','on',... 'pos',8); set(findobj(emenu,'label','Cu&t'),'pos',9); set(findobj(emenu,'label','&Copy'),'pos',10); set(findobj(emenu,'label','&Paste'),'pos',11); set(findobj(emenu,'label','&Select All'),'pos',12); set(findobj(emenu,'label','Copy &Figure'),'pos',13); set(findobj(emenu,'label','Copy &Options'),'pos',14); set(findobj(emenu,'label','F&igure Properties'),'pos',15); set(findobj(emenu,'label','&Axes Properties'),'pos',16); set(findobj(emenu,'label','C&urrent Object Properties'),'pos',17); % Options menu menu(1) = uimenu('label','Options','visible','off','pos',3); menukey = uimenu(menu(1),'label','Keyboard input.','call',... 'dfield8(''kbd'')'); mesev = uimenu(menu(1),'label','Plot several solutions.',... 'call','dfield8(''several'')'); menulevel = uimenu(menu(1),'label','Plot level curves.',... 'call','dfield8(''level'')',... 'separator','off','tag','level'); meexportdata = uimenu(menu(1),'label','Export solution data.',... 'call','dfield8(''export'')',... 'separator','off','tag','dexp'); plcall = [ 'ud = get(gcf,''user'');',... 'me = gcbo;',... 'label = get(me,''label'');',... 'if strcmp(label,''Show the phase line.''),',... ' set(me,''label'',''Hide the phase line.'');',... ' ud.pline = ''on'';',... ' set(ud.plineh,''vis'',''on'');',... ' set(gcf,''user'',ud);',... 'else,',... ' set(me,''label'',''Show the phase line.'');',... ' ud.pline = ''off'';',... ' set(ud.plineh,''vis'',''off'');',... ' kk = find(ishandle(ud.plhand));',... ' delete(ud.plhand(kk));',... ' ud.plhand = ;',... ' set(gcf,''user'',ud);',... 'end']; mepline = uimenu(menu(1),'label','Show the phase line.',... 'call',plcall,'tag','pline','separator','on'); mesolvset = uimenu(menu(1),'label','Solver settings.',... 'call','dfield8(''solvset'')'); mesolve = uimenu(menu(1),'label','Solver.'); solverstr = ['ud = get(gcf,''user'');',... 'me = gcbo;',... 'meud = get(me,''user'');',... 'ud.settings.refine = meud.refine;',... 'ud.settings.tol = meud.tol;',... 'ud.settings.solver = meud.solver;',... 'ud.settings.solvhandle = meud.solvhandle;',... 'ud.settings.stepsize = meud.stepsize;',... 'ud.settings.hmax = meud.hmax;',... 'set(ud.solver,''checked'',''off'');',... 'set(me,''checked'',''on'');',... 'set(gcf,''user'',ud);',... 'dfset = findobj(''name'',''dfield8 Setup'');',... 'sud = get(dfset,''user'');',... 'sud.settings = ud.settings;',... 'set(dfset,''user'',sud);',... 'dfield8(''solvset'');']; solver = dud.settings.solver; dpset.refine = 4; dpset.tol = 1e6; dpset.solver = 'DormandPrince'; dpset.solvhandle = @dfdp45; dpset.stepsize = 0; dpset.hmax = 0; if strcmp(solver,'DormandPrince') dpch = 'on'; else dpch = 'off'; end eulset.refine = 1; eulset.tol = 0; eulset.solver = 'Euler'; eulset.solvhandle = @dfeul; eulset.stepsize = 0.1; eulset.hmax = 0; if strcmp(solver,'Euler') eulch = 'on'; else eulch = 'off'; end rk2set.refine = 1; rk2set.tol = 0; rk2set.solver = 'RungeKutta 2'; rk2set.solvhandle = @dfrk2; rk2set.stepsize = 0.1; rk2set.hmax = 0; if strcmp(solver,'RungeKutta 2') rk2ch = 'on'; else rk2ch = 'off'; end rk4set.refine = 1; rk4set.tol = 0; rk4set.solver = 'RungeKutta 4'; rk4set.solvhandle = @dfrk4; rk4set.stepsize = 0.1; rk4set.hmax = 0; if strcmp(solver,'RungeKutta 4') rk4ch = 'on'; else rk4ch = 'off'; end dud.solver(1) = uimenu(mesolve,'label','Dormand Prince',... 'checked',dpch,... 'call',solverstr,'user',dpset); dud.solver(2) = uimenu(mesolve,'label','Euler',... 'checked',eulch,... 'call',solverstr,'user',eulset); dud.solver(3) = uimenu(mesolve,'label','Runge Kutta 2',... 'checked',rk2ch,... 'call',solverstr,'user',rk2set); dud.solver(4) = uimenu(mesolve,'label','Runge Kutta 4',... 'checked',rk4ch,... 'call',solverstr,'user',rk4set); medir = uimenu(menu(1),'label','Solution direction.'); directionstr = ['ud = get(gcf,''user'');',... 'me = gcbo;',... 'ud.dir = get(me,''user'');',... 'set(ud.direction,''checked'',''off'');', ... 'set(me,''checked'',''on'');',... 'set(gcf,''user'',ud);']; dud.direction(1) = uimenu(medir,'label','Both',... 'checked','on',... 'user',0,... 'call',directionstr); dud.dir = 0; dud.direction(2) = uimenu(medir,'label','Forward',... 'user',1,... 'call',directionstr); dud.direction(3) = uimenu(medir,'label','Back',... 'user',1,... 'call',directionstr); meset = uimenu(menu(1),'label','Window settings.',... 'call','dfield8(''settings'')'); menu(6) = uimenu(menu(1),'label','Make the Display Window inactive.',... 'call','dfield8(''hotcold'')','separator','on'); % View menu set(findobj(gcf,'label','&View'),'pos',4); set(findobj(gcf,'label','&Figure Toolbar'),... 'call','dfield8(''showbar'')'); dud.menu = menu; set(dfdisp,'ToolBar','none'); set(0,'showhiddenhandles',hhsetup); set(gcf,'WindowButtonDownFcn','dfield8(''down'')'); set(dfdisp,'WindowButtonMotionFcn','dfield8(''cdisp'')' ); dud.uicont = [nframe,dud.notice,dbutt([1 2 3])]; hh1 = [dud.axes,nframe,dud.notice,dbutt([1 2 3])]; set(hh1,'units','norm'); hh2 = [nframe,dud.notice,dbutt(2:3),dud.axes,dud.menu(1)]; set(hh2,'visible','on'); set(dfdisp,'vis','on'); dud.printstr = 'print noui'; dud.pline = 'off'; dud.arr = ; dud.solhand = ; dud.plhand = ; dud.level = ' '; dud.contours = zeros(0,1); end % if (~isempty(dfdisp)) & else dfdispa = dud.axes; axes(dfdispa); xlabel(Tname); ylabel(Xname); hv = get(0,'showhiddenhandles'); set(0,'showhiddenhandles','on'); set(findobj('tag','zbmenu'),'enable','off'); set(0,'showhiddenhandles',hv); pf = pflag; k = find(pflag); if ~isempty(k) tstr = [tstr,' ']; for j = 1:length(k) tstr = [tstr,' ',pstring{k(j)}]; end end title(tstr) % Initialize important information as user data. dud.function = dfcn; if ~isempty(dud.solhand) delete(dud.solhand); end dud.solhand = ; % Handles to solution curves. if isstruct(dud.arr) hand = [dud.arr.lines;dud.arr.arrows]; delete(hand); end dud.arr = ; % Handles for the direction and vector fields. dud.wmat = ; set(findobj('tag','pline'),'label','Show the phase line.'); dud.pline = 'off'; kk = find(ishandle(dud.plhand)); delete(dud.plhand(kk)); dud.plhand = ; dud.color = sud.color; dud.fieldtype = Arrflag; dud.npts = NumbFPts; ud.y = zeros(2,1); ud.i = 0; ud.line = 0; wind = dud.syst.wind(:); dwind = [wind(1); wind(3); wind(2); wind(4)]; DY = [wind(2)wind(1); wind(4)wind(3)]; ud.DY = DY; ud.cwind = wind dud.settings.magn*[DY(1); DY(1);DY(2);DY(2)]; ud.stop = 0; ud.gstop = 1; ud.plot = 1; hmax = DY(1)/10; dud.settings.hmax = hmax; mud = get(dud.solver(1),'user'); mud.hmax = hmax; set(dud.solver(1),'user',mud); set(dfdisp,'user',dud); set(dud.axes,'user',ud); ppkbd = findobj('name','dfield8 Keyboard input','vis','on'); if ~isempty(ppkbd),dfield8('kbd'),end dfield8('dirfield',dfdisp); end elseif strcmp(action,'dirfield') % 'dirfield' computes and plots the field elements. This is the entry % point both from 'proceed' and from later commands that require the % recomputation of the field elements. % Find dfield8 Display and get the user data. disph = input1; dud = get(disph,'user'); color = dud.color; dfcn = dud.function; dfdispa = dud.axes; WINvect = dud.syst.wind; settings = dud.settings; notice = dud.notice; if notice nstr = get(notice,'string'); nstr(1:4)=nstr(2:5); nstr{5,1} = 'Computing the field elements.'; set(notice,'string',nstr); % Augment the window matrix wmat = dud.wmat; wrows = size(wmat,1); wflag = 0; for k = 1:wrows if wmat(k,:)==WINvect wflag = 1; end end if wflag == 0 wmat = [wmat;WINvect]; dud.wmat = wmat; end if wrows hv = get(0,'showhiddenhandles'); set(0,'showhiddenhandles','on'); hhh = findobj('tag','zbmenu'); set(hhh,'enable','on'); set(0,'showhiddenhandles',hv); end end Tmin = WINvect(1); Tmax = WINvect(2); Xmin = WINvect(3); Xmax = WINvect(4); N = dud.npts; deltax=(Xmax Xmin)/(N1); deltat=(Tmax Tmin)/(N1); % Set up the display window. Dxint=[Xmindeltax,Xmax+deltax]; Dtint=[Tmindeltat,Tmax+deltat]; % Set up the original mesh. XXXg=Xmin + deltax*[0:N1]; TTTg=Tmin + deltat*[0:N1]; [Tt,Xx]=meshgrid(TTTg,XXXg); % Calculate the line and vector fields. Xx=Xx(:);Tt=Tt(:); Ww = zeros(size(Xx)); Ww = feval(dfcn,Tt',Xx'); Vv = ones(size(Ww)) + Ww*sqrt(1); Vv = Vv.'; Arrflag = dud.fieldtype; mgrid = Tt+Xx.*sqrt(1); % mgrid = mgrid(:); zz=Vv.'; sc = min(deltat,deltax); arrow=[1,1].'; zzz=sign(zz); scale = sqrt((real(zzz)/deltat).^2+ (imag(zzz)/deltax).^2); ww = (zzz == 0); scale = scale + ww; aa1 = 0.3*arrow*(zzz./scale) +ones(size(arrow))*(mgrid.'); [r,c] = size(aa1); aa1=[aa1;NaN*ones(1,c)]; aa1=aa1(:); arrow = [0,1,.7,1,.7].' + [0,0,.25,0,.25].' * sqrt(1); zz=sign(zz).*((abs(zz)).^(1/3)); scale = 0.9*sc./max(max(abs(zz))); aa2 = scale*arrow*zz +ones(size(arrow))*(mgrid.'); [r,c] = size(aa2); aa2=[aa2;NaN*ones(1,c)]; aa2=aa2(:); axes(dfdispa); arr = dud.arr; % Delete the old field data. if isstruct(arr) hand = [arr.lines;arr.arrows]; delete(hand); end arrh1 = plot(real(aa1),imag(aa1),'color',color.arrows,'visible' ,'off'); arrh2 = plot(real(aa2),imag(aa2),'color',color.arrows,'visible' ,'off'); % We plot both the line field and the vector field. Then we % control which is seen by manipulating the visibility. switch Arrflag case 'lines' set(arrh1,'visible','on'); case 'arrows' set(arrh2,'visible','on'); end dud.arr.lines = arrh1; % Save the handles for later use. dud.arr.arrows = arrh2; % Save the handles for later use. if notice nstr = get(notice,'string'); nstr(1:4) = nstr(2:5); nstr{5,1} = 'Ready.'; set(notice,'string',nstr); end axis([Dtint,Dxint]); aa = Dtint(1) + (Dtint(2) Dtint(1))/100; if ~isempty(dud.plhand) set(dud.plhand,'xdata',aa); end if (isfield(dud,'plineh') & (~isempty(dud.plineh))) set(dud.plineh,'xdata',[aa,aa],'ydata',Dxint); else dud.plineh = plot([aa,aa],Dxint,'color',dud.color.pline); end set([dud.plhand;dud.plineh],'vis',dud.pline); set(disph,'user',dud); elseif strcmp(action,'hotcold') % 'hotcold' is the callback for the menu selection that makes the % Display Window active or inactive. dfdisp = gcf; dud = get(dfdisp,'user'); nstr = get(dud.notice,'string'); nstr(1:4) = nstr(2:5); mehc = dud.menu(6); if (findstr(get(mehc,'label'),'inactive')) set(dfdisp,'WindowButtonDownFcn',' '); set(mehc,'label','Make the Display Window active.'); nstr{5,1} = 'The Display Window is not active.'; set(dud.notice,'string',nstr); else set(dfdisp,'WindowButtonDownFcn','dfield8(''down'')'); set(mehc,'label','Make the Display Window inactive.'); nstr{5,1} = 'The Display Window is active.'; set(dud.notice,'string',nstr); end elseif strcmp(action,'down') % 'down' is the Window Button Down call. It starts the computation of % solutions from a click of the mouse. disph = gcf; seltype = get(disph,'selectiontype'); if strcmp(seltype,'alt') dfield8('zoom'); return end dud = get(disph,'user'); ax = dud.axes; ch = findobj('type','uicontrol','enable','on'); % mh = findobj('type','uimenu','enable','on'); set(ch,'enable','inactive'); % set(mh,'enable','off'); wbdf = get(disph,'WindowbuttonDownFcn'); set(disph,'WindowbuttonDownFcn',''); axes(ax); initpt = get(ax,'currentpoint'); initpt = initpt(1,[1,2]); dfield8('solution',initpt,disph); set(disph,'WindowbuttonDownFcn',wbdf); % set([ch;mh],'enable','on'); set(ch,'enable','on'); notice = dud.notice; if notice nstr = get(notice,'string'); nstr(1:4) = nstr(2:5); nstr{5,1} = 'Ready.'; set(notice,'string',nstr) end elseif strcmp(action,'several') % 'several' allows the user to pick several initial points at once. % This is not needed in Xwindows, but it is on the Macintosh. disph = gcf; ch = findobj('type','uicontrol','enable','on'); % mh = findobj('type','uimenu','enable','on'); set(ch,'enable','inactive'); % set(mh,'enable','off') wbdf = get(disph,'WindowbuttonDownFcn'); set(disph,'WindowbuttonDownFcn',wbdf); dud = get(disph,'user'); notice = dud.notice; if notice nstr = get(notice,'string'); nstr(1:4) = nstr(2:5); nstr{5,1} = ['Pick initial points with the mouse. ',... 'Enter "Return" when finished.']; set(notice,'string',nstr) end [X,Y]=ginput; NN = length(X); for k = 1:NN initpt = [X(k),Y(k)]; dfield8('solution',initpt,disph); end if notice nstr = get(notice,'string'); nstr(1:4) = nstr(2:5); nstr{5,1} = 'Ready.'; set(notice,'string',nstr); end % set([ch;mh],'enable','on'); set(ch,'enable','on'); set(disph,'WindowbuttonDownFcn','dfield8(''down'')'); elseif strcmp(action,'solution') % 'solution' effects the computation and (erasemode == none) plotting of % solutions. It also stores the data as appropriate. disph = input2; dud = get(disph,'user'); tcol = dud.color.temp; pcol = dud.color.orb; notice = dud.notice; initpt = input1(:); dfcn = dud.function; dfdispa = dud.axes; aud=get(dfdispa,'user'); wind = aud.cwind; AA = wind(1); BB = wind(2); settings = dud.settings; ptstr = [' (',num2str(initpt(1),2), ', ', num2str(initpt(2),2), ')']; refine = settings.refine; tol = settings.tol; ud = get(dud.axes,'user'); rtol = tol; atol = tol*ud.DY*1e4'; if length(initpt) == 2 switch dud.dir case 0 intplus = [initpt(1), BB]; intminus = [initpt(1), AA]; case 1 intplus = [initpt(1), initpt(1)]; intminus = [initpt(1), AA]; case 1 intplus = [initpt(1), BB]; intminus = [initpt(1), initpt(1)]; end else intplus = [initpt(1),initpt(4)]; intminus = [initpt(1),initpt(3)]; initpt = initpt([1:2]); end stopbutt =findobj('tag','stop'); set(stopbutt,'vis','on','enable','on'); solvhandle = settings.solvhandle; cflag = 0; if intplus(2)>intplus(1) cflag = cflag + 1; if notice nstr = get(notice,'string'); nstr(1:4) = nstr(2:5); nstr{5} = ['The forward orbit from',ptstr]; set(notice,'string',nstr); end drawnow [tp,xp] = feval(solvhandle,dfcn,intplus,initpt(2),disph); aud = get(dfdispa,'user'); hnew1 = aud.line; set(aud.pline,'erase','normal','color', pcol); dud.plhand=[dud.plhand;aud.pline]; end if intminus(2) < intminus(1) cflag = cflag + 2; if notice nstr = get(notice,'string'); nstr(1:4) = nstr(2:5); nstr{5} = ['The backward orbit from',ptstr]; set(notice,'string',nstr); end drawnow [tm,xm] = feval(solvhandle,dfcn,intminus,initpt(2),disph); aud = get(dfdispa,'user'); hnew2 = aud.line; set(aud.pline,'erase','normal','color', pcol); dud.plhand=[dud.plhand;aud.pline]; set(stopbutt,'vis','off'); end % if intminus(2) < intminus(1) % Store the trajectory. switch cflag case 1 % positive only set(hnew1,'xdata',tp(:),'ydata',xp(:),'color',pcol); set(hnew1,'erase','normal'); dud.solhand = [dud.solhand;hnew1]; case 2 % negative only x = flipud(xm); t = flipud(tm); set(hnew2,'xdata',t(:),'ydata',x(:),'color',pcol); set(hnew2,'erase','normal'); dud.solhand = [dud.solhand;hnew2]; case 3 % both directions x = flipud(xm); t = flipud(tm); x=[x;xp]; t=[t;tp]; delete(hnew1); set(hnew2,'xdata',t(:),'ydata',x(:),'color',pcol); set(hnew2,'erase','normal'); dud.solhand = [dud.solhand;hnew2]; end % switch cflag set(disph,'user',dud); elseif strcmp(action,'kcompute') % 'kcompute' is the call back for the Compute % button on the dfield8 Keyboard figure. compute = 1; kh = get(gcf,'user'); dfdisp = findobj('name','dfield8 Display'); if (isempty(dfdisp)) dfield8('confused'); end dud = get(dfdisp,'user'); dfdispa = dud.axes; aud = get(dfdispa,'user'); dfset = findobj('name','dfield8 Setup'); sud = get(dfset,'user'); ch = findobj('type','uicontrol','enable','on'); set(ch,'enable','inactive'); set(dfdisp,'WindowbuttonDownFcn',''); xstr = get(kh.xval,'string'); tstr = get(kh.tval,'string'); pnameh = sud.h.pname; pvalh = sud.h.pval; pflag = zeros(1,4); perr = ; for kk = 1:4; pn = char(get(pnameh(kk),'string')); pv = char(get(pvalh(kk),'string')); if ~isempty(pn) if isempty(pv) perr = pvalh(kk); else xstr = dfield8('paraeval',pn,pv,xstr); tstr = dfield8('paraeval',pn,pv,tstr); end end end xvalue = str2num(xstr); tvalue = str2num(tstr); if get(kh.spec,'value') t0 = str2num(get(kh.t0,'string')); tf = str2num(get(kh.tf,'string')); initpt = [tvalue,xvalue,t0,tf]; if (length(initpt) ~= 4) warndlg({'Values must be entered for all of the entries.'},... 'Illegal input'); compute = 0; elseif tf <= t0 warndlg({'The final time of the computation interval';... 'must be smaller than the initial time.'},'Illegal input'); compute = 0; elseif (tvalue < t0) | (tvalue > tf) warndlg('The initial time must be in the computation interval.',... 'Illegal input'); compute = 0; end aud.gstop = 0; set(dfdispa,'user',aud); else initpt = [tvalue,xvalue]; if (length(initpt) ~= 2) warndlg({'Values must be entered for all of the entries.'},... 'Illegal input'); compute = 0; end end % if get(kh.spec,'value') if compute dfield8('solution',initpt,dfdisp); end nstr = get(dud.notice,'string'); nstr(1:4) = nstr(2:5); nstr{5} = 'Ready.'; set(dud.notice,'string',nstr) % set([ch;mh],'enable','on'); set(ch,'enable','on'); set(dfdisp,'WindowbuttonDownFcn','dfield8(''down'')'); aud.gstop = 1; set(dfdispa,'user',aud); elseif strcmp(action,'kbd') % 'kbd' is the callback for the Keyboard Input menu selection. It % sets up the dfield8 Keyboard figure which allows accurate input of % initial values using the keyboard. ppkbd = findobj('name','dfield8 Keyboard input'); if ~isempty(ppkbd) delete(ppkbd); end dfdisp = gcf; dud = get(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Engineering Mathematics

Authors: ERWIN KREYSZIG

9th Edition

0471488852, 978-0471488859

More Books

Students also viewed these Mathematics questions

Question

What does unduly high performance indicate?

Answered: 1 week ago