-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchebguiwindow.m
1756 lines (1452 loc) · 60.3 KB
/
chebguiwindow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = chebguiwindow(varargin)
% CHEBGUIWINDOW Driver file for Chebfun's CHEBGUI
% This m-file populates and controls Chebfun's CHEBGUI.
%
% See also chebgui
% Copyright 2011 by The University of Oxford and The Chebfun Developers.
% See http://www.maths.ox.ac.uk/chebfun/ for Chebfun information.
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @chebguiwindow_OpeningFcn, ...
'gui_OutputFcn', @chebguiwindow_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
warnstate = warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid');
try
gui_mainfcn(gui_State, varargin{:});
warning(warnstate);
catch ME
warning(warnstate)
MEID = ME.identifier;
if ~isempty(strfind(MEID,'Chebgui:'))
% These are expected GUI errors. We only show the dialog
errordlg(cleanErrorMsg(ME.message), 'Chebgui error', 'modal');
uiwait
resetComponents(varargin{4});
% If in debug mode, we throw the error to the command window as
% well
if get(varargin{4}.menu_debug,'UserData')
rethrow(ME)
end
else
% Show an error dialog, but also throw the error to the command
% window
errordlg(cleanErrorMsg(ME.message), 'Chebgui error', 'modal');
uiwait
resetComponents(varargin{4});
rethrow(ME)
end
end
end
% End initialization code - DO NOT EDIT
% --- Executes just before chebguiwindow is made visible.
function chebguiwindow_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see Output(1-x^2)*exp(-30*(x+.5)^2)Fcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to chebguiwindow (see VARARGIN)
% Choose default command line output for chebguiwindow
handles.output = hObject;
initialisefigures(handles)
% Variable that determines whether a solution is available
handles.hasSolution = 0;
% Variable which stores the initial guess/condition
handles.init = [];
% Variable which stores imported variables from workspace
handles.importedVar = struct;
% Get the GUI object from the input argument
if ~isempty(varargin)
handles.guifile = varargin{1};
else
cgTemp = chebgui('type','bvp');
handles.guifile = loadexample(cgTemp,-1); % Load a random example
end
% Create a new structure which contains information about the latest
% solution obtained
handles.latest = struct;
% Store the default length of pausing between plots for BVPs and the
% tolerance in the userdata field of relevant menu objects.
set(handles.menu_odeplottingpause,'UserData','0.5');
set(handles.menu_tolerance,'UserData','1e-10');
% Create UserData for the Fix-Y-axis options (so that we can display
% something if it gets called without selecting a demo).
set(handles.menu_pdefixon,'UserData',{''});
% Populate the Demos menu, but only once (i.e. if user calls chebgui again,
% don't reload the examples).
if isempty(get(handles.menu_demos,'UserData'))
loaddemo_menu(handles.guifile,handles);
handles.demosLoaded = 1;
end
% Load the input fields
loadfields(handles.guifile,handles);
% Make sure the GUI starts in the correct mode
switchmode(handles.guifile,handles,handles.guifile.type);
% Get the system font size and store in handles
s = char(com.mathworks.services.FontPrefs.getCodeFont);
if s(end-2) == '='
fs = round(3/4*str2num(s(end-1)));
else
fs = round(3/4*str2num(s(end-2:end-1)));
end
set(handles.tempedit,'FontSize',fs);
% set(handles.check_uselatest,'String',{'Use latest';'solution'});
% Set the solve button to green
set(handles.button_solve,'String','Solve');
set(handles.button_solve,'BackgroundColor',[43 129 86]/256);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes chebguiwindow wait for user response (see UIRESUME)
% uiwait(handles.chebguimainwindow);
% --- Outputs from this function are returned to the command line.
function varargout = chebguiwindow_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
if nargout > 0,
varargout{1} = handles.output;
end
% If nargout == 2, return the fll set of handles
if nargout > 1,
varargout{2} = handles;
end
% -------------------------------------------------------------------------
% ---------- Callback functions for the objects of the GUI ----------------
% -------------------------------------------------------------------------
% -------------------------------------------------------------------------
% ------------- Functions which call chebgui methods ----------------------
% -------------------------------------------------------------------------
function button_clear_Callback(hObject, eventdata, handles)
if strcmp(get(handles.button_clear,'String'),'Clear all')
[newGUI handles] = cleargui(handles.guifile,handles);
handles.guifile = newGUI;
guidata(hObject, handles);
elseif strcmp(get(handles.button_clear,'String'),'Pause')
set(handles.button_clear,'String','Continue');
set(handles.button_clear,'BackgroundColor',[43 129 86]/256);
% Re-enable figure buttons
set(handles.button_figsol,'Enable','on');
set(handles.button_fignorm,'Enable','on');
else
% Disable figure buttons
set(handles.button_figsol,'Enable','off');
set(handles.button_fignorm,'Enable','off');
set(handles.button_clear,'String','Pause');
set(handles.button_clear,'BackgroundColor',[255 179 0]/256);
end
function button_solve_Callback(hObject, eventdata, handles)
% uicontrol(handles.panel_input)
% figure(handles.chebguimainwindow)
% set(hObject, 'Enable', 'off');
% drawnow;
% set(hObject, 'Enable', 'on');
handles = solveGUI(handles.guifile,handles);
guidata(hObject, handles);
function input_LBC_Callback(hObject, eventdata, handles)
newString = cellstr(get(hObject,'String'));
newString = removeTabs(newString); % Remove tabs
set(hObject,'String',newString);
handles = callbackBCs(handles.guifile,handles,newString,'lbc');
handles.guifile.LBC = newString;
guidata(hObject, handles);
function input_RBC_Callback(hObject, eventdata, handles)
newString = cellstr(get(hObject,'String'));
newString = removeTabs(newString); % Remove tabs
set(hObject,'String',newString);
handles = callbackBCs(handles.guifile,handles,newString,'rbc');
handles.guifile.RBC = newString;
guidata(hObject, handles);
% -------------------------------------------------------------------------
% --------- Functions which do their work without chebgui methods ---------
% -------------------------------------------------------------------------
function dom_left_Callback(hObject, eventdata, handles)
% Store the contents of input1_editText as a string. if the string
% is not a number then input will be empty
input = str2num(get(hObject,'String'));
% Checks to see if input is not numeric or empty. If so, default left end
% of the domain is taken to be -1.
if isempty(input) || isnan(input)
warndlg('Left endpoint of domain unrecognized, default value -1 used.')
set(hObject,'String','-1')
end
set(handles.input_GUESS,'Enable','on');
set(handles.toggle_useLatest,'Value',0);
set(handles.toggle_useLatest,'Enable','off');
handles.guifile.DomLeft = get(hObject,'String');
guidata(hObject, handles);
function dom_right_Callback(hObject, eventdata, handles)
input = str2num(get(hObject,'String'));
% Checks to see if input is not numeric or empty. If so, default right end
% of the domain is taken to be 1.
if isempty(input) || isnan(input)
warndlg('Right endpoint of domain unrecognized, default value 1 used.')
set(hObject,'String','1')
end
set(handles.input_GUESS,'Enable','on');
set(handles.toggle_useLatest,'Value',0);
set(handles.toggle_useLatest,'Enable','off');
handles.guifile.DomRight = get(hObject,'String');
guidata(hObject, handles);
function input_domain_Callback(hObject, eventdata, handles)
in = get(hObject,'String');
input = str2num(in);
% Checks to see if input is not numeric or empty. If so, default left end
% of the domain is taken to be -1.
if input(1) >= input(end)
warndlg('Empty domain. Default value [-1,1] used.')
in = '[-1,1]';
set(hObject,'String',in);
elseif isempty(input) || any(isnan(input)) || length(input)<2
warndlg('Domain unrecognized. Default value [-1,1] used.')
in = '[-1,1]';
set(hObject,'String',in);
elseif ~any(strfind(in,'['))
in = ['[' in ']'];
set(hObject,'String',in);
end
set(handles.input_GUESS,'Enable','on');
set(handles.toggle_useLatest,'Value',0);
set(handles.toggle_useLatest,'Enable','off');
handles.guifile.domain = in;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function input_domain_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% -------------------------------------------------------------------------
% ------- Functions which do their work in a couple of lines of code ------
% -------------------------------------------------------------------------
function input_GUESS_Callback(hObject, eventdata, handles)
newString = cellstr(get(hObject,'String'));
% Remove tabs
newString = removeTabs(newString);
set(hObject,'String',newString);
handles.guifile.init = newString;
if isempty(newString) || (iscell(newString) && numel(newString)==1 && isempty(newString{1}))
handles.init = '';
axes(handles.fig_sol);
cla(handles.fig_sol,'reset');
guidata(hObject, handles);
return
end
loadVariables(handles.importedVar)
guidata(hObject, handles);
xtTemp = chebfun('x',str2num(handles.guifile.domain));
% handles.init
if ~exist('r','var'), r = xtTemp; end
if ~exist('x','var'), x = xtTemp; end
if ~exist('t','var'), t = xtTemp; end
% Do something clever with multilines
str = cellstr(get(hObject,'String'));
init = [];
for k = 1:numel(str)
strk = str{k};
equalSigns = find(strk=='=');
if numel(equalSigns) > 1
error('Chebgui:InitInput','Too many equals signs in input.');
elseif numel(equalSigns) == 1
strk = strk(equalSigns+1:end);
elseif numel(str) > 1
error('Chebgui:InitInput',...
'Error constructing initial guess. Input must include the names of the dependent variables, i.e. be on the form "u = %s",...',strk)
end
strk = deblank(vectorize(strk));
try
if ~isempty(strk)
init = [init eval(strk)];
end
catch ME
error('Chebgui:InitInput',ME.message)
end
end
handles.init = init;
axes(handles.fig_sol);
plot(handles.init,'linewidth',2)
if ~isempty(handles.guifile.options.fixYaxisLower)
ylim([str2num(handles.guifile.options.fixYaxisLower) ...
str2num(handles.guifile.options.fixYaxisUpper)]);
end
if handles.guifile.options.grid, grid on, end
guidata(hObject, handles);
function loadVariables(importedVar)
fNames = fieldnames(importedVar);
for i=1:length(fNames), assignin('caller',fNames{i},importedVar.(fNames{i})), end
function input_DE_Callback(hObject, eventdata, handles)
str = cellstr(get(hObject,'String'));
% Remove tabs
str = removeTabs(str);
% Update the DE input and store in guifile
set(handles.input_DE,'String',str);
handles.guifile.DE = str;
% Auto PDE and EIG detection
for k = 1:numel(str)
strk = str{k};
if any(strfind(strk,'_'))
if ~get(handles.button_pde,'value')
handles = switchmode(handles.guifile,handles,'pde');
end
break
elseif any(strfind(strk,'lam') | strfind(strk,'lambda'))
if ~get(handles.button_eig,'value')
handles = switchmode(handles.guifile,handles,'eig');
end
break
end
end
guidata(hObject, handles);
function str = removeTabs(str)
for k = 1:numel(str)
idx = 1;
strk = str{k};
while ~isempty(idx)
idx = strfind(strk,double(9));
strk(idx) = [];
end
str{k} = strk;
end
%% Keypresses
function input_DE_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab'),
if strcmp(eventdata.Modifier,'shift')
if get(handles.button_pde,'value')
uicontrol(handles.input_timedomain);
else
uicontrol(handles.input_domain);
end
elseif get(handles.button_pde,'value')
uicontrol(handles.input_LBC);
else
uicontrol(handles.input_BC);
end
end
function input_BC_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
uicontrol(handles.input_DE);
else
uicontrol(handles.input_GUESS);
end
end
function input_LBC_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
uicontrol(handles.input_DE);
else
uicontrol(handles.input_RBC);
end
end
function input_RBC_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
uicontrol(handles.input_LBC);
else
uicontrol(handles.input_GUESS);
end
end
function input_GUESS_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
uicontrol(handles.input_BC);
else
uicontrol(handles.button_solve);
set(handles.button_solve,'selected','on');
end
end
function popupmenu_sigma_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
uicontrol(handles.edit_eigN);
else
uicontrol(handles.button_solve);
end
end
function button_solve_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
if get(handles.button_eig,'value')
uicontrol(handles.input_BC);
else
uicontrol(handles.input_GUESS);
end
else
uicontrol(handles.button_clear);
end
elseif strcmp(eventdata.Key,'return')
button_solve_Callback(hObject, eventdata, handles);
end
function button_clear_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
uicontrol(handles.button_solve);
else
uicontrol(handles.button_export);
end
elseif strcmp(eventdata.Key,'return')
button_clear_Callback(hObject, eventdata, handles);
end
function button_export_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key,'tab')
if strcmp(eventdata.Modifier,'shift')
uicontrol(handles.button_clear);
elseif get(handles.button_exportsoln,'enabled')
uicontrol(handles.button_exportsoln);
else
uicontrol(handles.input_domain);
end
elseif strcmp(eventdata.Key,'return')
button_export_Callback(hObject, eventdata, handles);
end
%%
function input_timedomain_Callback(hObject, eventdata, handles)
str = get(hObject,'String');
if iscell(str), str = str{:}; end
num = str2num(str);
options.WindowStyle = 'modal';
% Indicates we had timedomain with negative spacing (0:-.1:1)
while isempty(num)
str = inputdlg('Time domain should be a vector of length >2, with positive spacing, at which times solution is returned','Set time domain',...
1,{'0:.1:1'},options);
if isempty(str), str = ''; break, end
str = str{:};
num = str2num(str);
end
while (~isempty(str) && numel(num) < 3)
h = (num(2)-num(1))/20;
def = sprintf('%s:%s:%s',num2str(num(1),'%0.0f'),num2str(h,'%0.2g'),num2str(num(2),'%0.0f'));
str = inputdlg('Time domain should be a vector of length >2 at which times solution is returned','Set time domain',...
1,{def},options);
if isempty(str), str = ''; break, end
str = str{:};
num = str2num(str);
end
set(handles.input_timedomain,'String',str);
handles.guifile.timedomain = str;
guidata(hObject, handles);
% -------------------------------------------------------------------------
% -------------------- Unsorted functions --------------------------------
% -------------------------------------------------------------------------
function button_fignorm_Callback(hObject, eventdata, handles)
% Check the type of the problem
if get(handles.button_ode,'Value');
latestNorms = handles.latest.norms;
figure;
semilogy(latestNorms,'-*','Linewidth',2),title('Norm of updates'), xlabel('Number of iteration')
if length(latestNorms) > 1
XTickVec = 1:max(floor(length(latestNorms)/5),1):length(latestNorms);
set(gca,'XTick', XTickVec), xlim([1 length(latestNorms)]), grid on
else % Don't display fractions on iteration plots
set(gca,'XTick', 1)
end
elseif get(handles.button_pde,'Value');
u = handles.latest.solution;
tt = handles.latest.solutionT;
varnames = handles.varnames;
xLab = handles.indVarName{1};
tLab = handles.indVarName{2};
if ~iscell(u)
figure
waterfall(u,tt,'simple','linewidth',2)
xlabel(xLab), ylabel(tLab); zlabel(varnames{1});
else
figure
for k = 1:numel(u)
subplot(1,numel(u),k);
waterfall(u{k},tt,'simple','linewidth',2)
xlabel(xLab), ylabel(tLab), zlabel(varnames{k})
title(varnames{k})
end
tmp = u{k}(:,1);
u1 = tmp.vals(1);
tmp = get(tmp,'vals');
x1 = tmp(1);
figure
cols = get(0,'DefaultAxesColorOrder');
for k = 1:numel(u)
plot3(x1,tt(1),u1,'linewidth',2,'color',cols(k,:)); hold on
end
legend(varnames{:})
for k = 1:numel(u)
waterfall(u{k},tt,'simple','linewidth',2,'edgecolor',cols(k,:))
end
xlabel(xLab), ylabel(tLab), grid on
end
else % eigs
figure, h1 = gca;
if strcmp(handles.latest.type,'eig')
selection = get(handles.iter_list,'Value');
ploteigenmodes(handles.guifile,handles,selection,[],h1);
end
end
function button_figsol_Callback(hObject, eventdata, handles)
if get(handles.button_ode,'Value');
latestSolution = handles.latest.solution;
figure
plot(latestSolution,'Linewidth',2), title('Solution at end of iteration')
xlabel(handles.indVarName);
varnames = handles.varnames;
if numel(varnames) == 1
ylabel(varnames)
end
% Turn on grid
if handles.guifile.options.grid, grid on, end
if numel(handles.varnames) > 1, legend(handles.varnames), end
elseif get(handles.button_pde,'Value');
u = handles.latest.solution;
tt = handles.latest.solutionT;
varnames = handles.varnames;
xLab = handles.indVarName{1};
tLab = handles.indVarName{2};
titleStr = sprintf('Solution at final time, %s = %f',tLab,tt(end));
figure
if ~iscell(u)
plot(u(:,end),'Linewidth',2)
xlabel(xLab);
ylabel(varnames);
title(titleStr)
else
v = chebfun;
for k = 1:numel(u)
uk = u{k};
v(:,k) = uk(:,end);
end
plot(v,'Linewidth',2);
xlabel(xLab);
legend(varnames);
title(titleStr)
end
% Turn on grid
if handles.guifile.options.grid, grid on, end
% Turn on fixed y-limits
if ~isempty(handles.guifile.options.fixYaxisLower)
ylim([str2num(handles.guifile.options.fixYaxisLower) ...
str2num(handles.guifile.options.fixYaxisUpper)]);
end
else
figure, h1 = gca;
if strcmp(handles.latest.type,'eig')
selection = get(handles.iter_list,'Value');
ploteigenmodes(handles.guifile,handles,selection,h1,[]);
end
end
function toggle_useLatest_Callback(hObject, eventdata, handles)
newVal = get(hObject,'Value');
if newVal % User wants to use latest solution
set(handles.input_GUESS,'String','Using latest solution');
set(handles.input_GUESS_cover,'Visible','On');
else
set(handles.input_GUESS,'String','');
set(handles.input_GUESS,'Enable','On');
set(handles.input_GUESS_cover,'Visible','Off');
handles.guifile.init = '';
end
guidata(hObject, handles);
% --- Executes when chebguimainwindow is resized.
function chebguimainwindow_ResizeFcn(hObject, eventdata, handles)
% hObject handle to chebguimainwindow (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function button_ode_Callback(hObject, eventdata, handles)
handles = switchmode(handles.guifile,handles,'bvp');
guidata(hObject, handles);
% --- Executes on button press in button_pde.
function button_pde_Callback(hObject, eventdata, handles)
handles = switchmode(handles.guifile,handles,'pde');
guidata(hObject, handles);
% --- Executes on button press in button_pde.
function button_eig_Callback(hObject, eventdata, handles)
handles = switchmode(handles.guifile,handles,'eig');
guidata(hObject, handles);
% --- Executes on selection change in iter_list.
function iter_list_Callback(hObject, eventdata, handles)
% Hints: contents = cellstr(get(hObject,'String')) returns iter_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from iter_list
% Selecting from the list only does something when we are in e-value mode
% Display corresponding e-funcs when clicking on e-value.
% set(handles.fig_sol,'XLimMode','Manual');
if strcmp(handles.latest.type,'eig')
selection = get(handles.iter_list,'Value');
ploteigenmodes(handles.guifile,handles,selection);
end
% xlim(handles.fig_norm,xlim_norm); ylim(handles.fig_norm,ylim_norm);
% -------------------------------------------------------------------------
% ---------------------- Other subfunctions -------------------------------
% -------------------------------------------------------------------------
function initialisefigures(handles)
cla(handles.fig_sol,'reset');
title('Solutions'), box on
cla(handles.fig_norm,'reset');
title('Updates'), box on
% -------------------------------------------------------------------------
% ----------------- All CreateFcn are stored here -------------------------
% -------------------------------------------------------------------------
function dom_left_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function dom_right_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input_DE_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input_RBC_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input_GUESS_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input_LBC_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function iter_list_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fig_logo_CreateFcn(hObject, eventdata, handles)
% Hint: place code in OpeningFcn to populate
f = chebpoly(10);
plot(f,'interval',[-1,.957],'linew',3), hold on
t = - cos(pi*(2:8)'/10) *0.99; % cheb extrema (tweaked)
y = 0*t;
h = text( t, y, num2cell(transpose('chebfun')), ...
'fontsize',16,'hor','cen','vert','mid') ;
flist = listfonts;
k = strmatch('Rockwell',flist); % 1st choice
k = [k; strmatch('Luxi Serif',flist)]; % 2nd choice
k = [k; strmatch('luxiserif',flist)]; % 2.5th choice
k = [k; strmatch('Times',flist)]; % 3rd choice
if ~isempty(k), set(h,'fontname',flist{k(1)}), end
axis([-1.02 .98 -2 2]), axis off
function fig_sol_CreateFcn(hObject, eventdata, handles)
% Hint: place code in OpeningFcn to populate fig_sol
function fig_norm_CreateFcn(hObject, eventdata, handles)
% Hint: place code in OpeningFcn to populate fig_norm
function input_timedomain_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function tempedit_CreateFcn(hObject, eventdata, handles)
function ylim1_CreateFcn(hObject, eventdata, handles)
function ylim1_Callback(hObject, eventdata, handles)
function ylim2_CreateFcn(hObject, eventdata, handles)
function ylim2_Callback(hObject, eventdata, handles)
function button_solve_ButtonDownFcn(hObject, eventdata, handles)
% -------------------------------------------------------------------------
% ----------------- Right-clicking functions ------------------------------
% -------------------------------------------------------------------------
function input_DE_ButtonDownFcn(hObject, eventdata, handles)
chebguiedit('chebguiwindow', handles.chebguimainwindow,'input_DE');
input_DE_Callback(hObject, eventdata, handles); % Go through the callback function
function input_LBC_ButtonDownFcn(hObject, eventdata, handles)
chebguiedit('chebguiwindow', handles.chebguimainwindow,'input_LBC');
input_LBC_Callback(hObject, eventdata, handles); % Go through the callback function
function input_RBC_ButtonDownFcn(hObject, eventdata, handles)
chebguiedit('chebguiwindow', handles.chebguimainwindow,'input_RBC');
input_RBC_Callback(hObject, eventdata, handles); % Go through the callback function
function input_GUESS_ButtonDownFcn(hObject, eventdata, handles)
chebguiedit('chebguiwindow', handles.chebguimainwindow,'input_GUESS');
input_GUESS_Callback(hObject, eventdata, handles); % Go through the callback function
function editfontsize_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% -------------------------------------------------------------------------
% ----------------- Callbacks for menu items ----------------------------
% -------------------------------------------------------------------------
% --------------------------------------------------------------------
function menu_file_Callback(hObject, eventdata, handles)
% hObject handle to menu_file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function menu_opengui_Callback(hObject, eventdata, handles)
[filename pathname filterindex] = uigetfile('*.guifile','Pick a file');
if ~filterindex, return, end
cgTemp = chebgui(fullfile(pathname,filename));
loadfields(cgTemp,handles);
handles.guifile = cgTemp;
if ~isempty(cgTemp.type)
handles = switchmode(cgTemp,handles,cgTemp.type);
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_savegui_Callback(hObject, eventdata, handles)
[filename pathname filterindex] = uiputfile('*.guifile','Pick a file');
if ~filterindex, return, end
% name = input('What would you like to name this GUI file? ');
name = '';
if get(handles.button_ode,'value')
demotype = 'bvp';
elseif get(handles.button_pde,'value')
demotype = 'pde';
else
demotype = 'eig';
end
dom = get(handles.input_domain,'string');
t = get(handles.input_timedomain,'string');
DE = get(handles.input_DE,'string');
BC = get(handles.input_BC,'string');
LBC = get(handles.input_LBC,'string');
RBC = get(handles.input_RBC,'string');
init = get(handles.input_GUESS,'string');
tol = '';
damping = '';
plotting = '';
DE = mycell2str(DE);
BC = mycell2str(BC);
LBC = mycell2str(LBC);
RBC = mycell2str(RBC);
init = mycell2str(init);
if strcmp(demotype,'pde')
s = sprintf(['''%s''\n', ...
'type = ''%s'';\n', ...
'domain = ''%s'';\n', ...
't = ''%s'';\n', ...
'DE = %s;\n', ...
'LBC = %s;\n', ...
'RBC = %s;\n', ...
'init = %s;\n', ...
'tol = ''%s'';\n', ...
'damping = ''%s'';\n', ...
'plotting = ''%s'';'], ...
name, demotype, dom, t, DE, LBC, RBC, init, tol, damping, plotting);
else
s = sprintf(['''%s''\n', ...
'type = ''%s'';\n', ...
'domain = ''%s'';\n', ...
'DE = %s;\n', ...
'BC = %s;\n', ...
'init = %s;\n', ...
'tol = ''%s'';\n', ...
'damping = ''%s'';\n', ...
'plotting = ''%s'';'], ...
name, demotype, dom, DE, BC, init, tol, damping, plotting);
end
fid = fopen(fullfile(pathname,filename),'w+');
fprintf(fid,s);
fclose(fid);
function out = mycell2str(in)
isc = iscell(in);
if ~isc
in = {in};
out = '';
else
out = '{';
end
for k = 1:numel(in)
if k > 1, out = [out ' ; ']; end
out = [out '''' strrep(in{k},'''','''''') ''''];
end
if isc
out = [out '}'];
end
% --------------------------------------------------------------------
function menu_demos_Callback(hObject, eventdata, handles)
function menu_bvps_Callback(hObject, eventdata, handles)
function menu_ivps_Callback(hObject, eventdata, handles)
function menu_systems_Callback(hObject, eventdata, handles)
function menu_help_Callback(hObject, eventdata, handles)
function menu_openhelp_Callback(hObject, eventdata, handles)
doc('chebgui')
% --------------------------------------------------------------------
function Untitled_9_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function menu_pdesingle_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function menu_pdesystems_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function menu_export_Callback(hObject, eventdata, handles)
% Offer more options if a solution exists.
if handles.hasSolution
set(handles.menu_exportmatfile,'Enable','on')
set(handles.menu_exportworkspace,'Enable','on')
else
set(handles.menu_exportmatfile,'Enable','off')
set(handles.menu_exportworkspace,'Enable','off')
end
% --------------------------------------------------------------------
function menu_exportmfile_Callback(hObject, eventdata, handles)
export(handles.guifile,handles,'.m')
function menu_exportchebgui_Callback(hObject, eventdata, handles)
export(handles.guifile,handles,'GUI')
function menu_exportworkspace_Callback(hObject, eventdata, handles)
export(handles.guifile,handles,'Workspace')
function menu_exportmatfile_Callback(hObject, eventdata, handles)
export(handles.guifile,handles,'.mat')
function menu_options_Callback(hObject, eventdata, handles)
function menu_close_Callback(hObject, eventdata, handles)
delete(handles.chebguimainwindow)
function uipanel13_DeleteFcn(hObject, eventdata, handles)
function tempedit_Callback(hObject, eventdata, handles)
function menu_odedampednewton_Callback(hObject, eventdata, handles)
function menu_odedampednewtonon_Callback(hObject, eventdata, handles)
handles.guifile.options.damping = '1';
set(handles.menu_odedampednewtonon,'checked','on');
set(handles.menu_odedampednewtonoff,'checked','off');
guidata(hObject, handles);
function menu_odedampednewtonoff_Callback(hObject, eventdata, handles)
handles.guifile.options.damping = '0';
set(handles.menu_odedampednewtonon,'checked','off');
set(handles.menu_odedampednewtonoff,'checked','on');
guidata(hObject, handles);
function menu_odeplotting_Callback(hObject, eventdata, handles)
function menu_pdeplotting_Callback(hObject, eventdata, handles)
function menu_odeplottingon_Callback(hObject, eventdata, handles)
% Obtain length of pause from handles
handles.guifile.options.plotting = get(handles.menu_odeplottingpause,'UserData');
set(handles.menu_odeplottingon,'checked','on');
set(handles.menu_odeplottingoff,'checked','off');
guidata(hObject, handles);