-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.m
847 lines (722 loc) · 27.3 KB
/
Main.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
function varargout = Main(varargin)
% MAIN MATLAB code for Main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Main_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Main
% Last Modified by GUIDE v2.5 03-May-2016 19:04:31
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Main_OpeningFcn, ...
'gui_OutputFcn', @Main_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
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Main is made visible.
function Main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% 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 Main (see VARARGIN)
% Choose default command line output for Main
handles.output = hObject;
set(handles.Rad_Real,'value',0);
set(handles.Rad_Img,'value',1);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Main_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
varargout{1} = handles.output;
% --------------------------------------------------------------------
function File_Callback(hObject, eventdata, handles)
% hObject handle to File (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Example_Callback(hObject, eventdata, handles)
% hObject handle to Example (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Help_Callback(hObject, eventdata, handles)
% hObject handle to Help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% hFont = uisetfont();
% mycolor = uisetcolor();
% h=dialog('name','帮助...','position',[700 400 250 120]);
% uicontrol('parent',h,'style','text','string','一次振荡奇异积分数值计算','position',[0 70 250 30],'fontsize',14);
% uicontrol('parent',h,'style','pushbutton','position',[100 10 60 35],'string','确定','callback','delete(gcbf)','fontsize',10);
% file = uigetfile('*.txt');
% open(file);
open Readme.txt;
% --------------------------------------------------------------------
function About_Callback(hObject, eventdata, handles)
% hObject handle to About (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=dialog('name','关于...','position',[700 400 250 140]);
uicontrol('parent',h,'style','text','string','WIT','position',[50 100 120 20],'fontsize',14);
uicontrol('parent',h,'style','text','string','计算机科学与工程学院','position',[44 60 180 20],'fontsize',12);
uicontrol('parent',h,'style','pushbutton','position',[100 10 60 35],'string','确定','callback','delete(gcbf)','fontsize',10);
% --------------------------------------------------------------------
function example1_Callback(hObject, eventdata, handles)
% hObject handle to example1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% v=get(handles.Rad_Real,'Value');
% set(handles.f,'String','exp(x)');
% if ~isequal(v,0)
% %eval(['f=@(x)','cos(w.*x).*',get(handles.f,'String'),'./(x-t)',';']);
% f=@(x)cos(w.*x).*exp(x)./(x-t);
% else
% %eval(['f=@(x)','sin(w.*x).*',get(handles.edit1,'String'),'./(x-t)',';']);
% f=@(x)sin(w.*x).*exp(x)./(x-t);
% end
% ezplot(f,[-1,6]);
%设置初始值
set(handles.w,'String','8,16,32,64');
w=[8,16,32,64];
set(handles.t,'String','0');
t=0;
set(handles.n,'String','3,4,5');
n=[3,4,5];
set(handles.f,'String','exp(x)');
v=get(handles.Rad_Real,'Value');
if ~isequal(v,0) %判断实部虚部
tag=1;
else
tag=0;
end
%开始计算
lw=length(w);
ln=length(n);
global Er;
Er=zeros(lw,ln); %误差表
global Er_gk;
Er_gk=zeros(lw,1);
%进度条
h=waitbar(0,'开始计算','Position',[500 300 275 60],'Name','计算进度...');
% pause(1);
hac=get(get(h,'children'),'children');
hapa=findall(hac,'type','patch');
set(hapa,'EdgeColor','b','FaceColor','g');
task=0;
for a=1:lw
v=get(handles.Rad_Real,'Value');
if ~isequal(v,0) %判断实部虚部
f=@(x)cos(w(a).*x).*exp(x)./(x-t);
else
f=@(x)sin(w(a).*x).*exp(x)./(x-t);
end
% eval(['fun=@(x)',get(handles.f,'String'),';']);
for b=1:ln
task=task+100/12;
waitbar(task/100,h,['已完成' num2str(task) '%']);
Er(a,b)=I_ErExp(f,w(a),n(b),t,tag);%计算误差
end
% [ I_gk ,Er_gk]=quadgk(f,-1,1,'AbsTol',1e-20,'RelTol',1e-10);
% [I_gk,Er_gk(a)]=quadgk(f,-1,1);
end
close(h);
%绘图
axes(handles.axes1);
legend off;
w=64;
if ~isequal(v,0) %判断实部虚部
f1=@(x)cos(w.*x).*exp(x)./(x-t);
else
f1=@(x)sin(w.*x).*exp(x)./(x-t);
end
legend off;
ezplot(f1,[-1,1]),legend('w=64'),grid on;
w=[8,16,32,64];
%计算Rate
Er(4,2)=Er(4,2);
Er(4,3)=Er(4,3);
Rate=log(Er(3,:)./Er(4,:))./log(2);
e=[Er;Rate];
c={ e(1,1),e(2,1),e(3,1),e(4,1),e(5,1);...
e(1,2),e(2,2),e(3,2),e(4,2),e(5,2);...
e(1,3),e(2,3),e(3,3),e(4,3),e(5,3)};
%设置表格
set(handles.Table,'RowName',{ num2str(w(1)), num2str(w(2)), num2str(w(3)),num2str(w(4)),'Rate'});
set(handles.Table,'ColumnName',{ num2str(n(1)), num2str(n(2)), num2str(n(3))});
set(handles.Table,'Data',c');
set(handles.Table,'UserData',c');
guidata(hObject, handles);
% --------------------------------------------------------------------
function example2_Callback(hObject, eventdata, handles)
% hObject handle to example2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%设置初始值
set(handles.w,'String','16,32,64,128');
w=[16,32,64,128];
set(handles.t,'String','-0.13');
t=-0.13;
set(handles.n,'String','3,4,5');
n=[3,4,5];
set(handles.f,'String','sinh(x)');
v=get(handles.Rad_Real,'Value');
if ~isequal(v,0) %判断实部虚部
tag=1;
else
tag=0;
end
%开始计算
lw=length(w);
ln=length(n);
global Er; %误差表
Er=zeros(lw,ln);
global Er_gk;
Er_gk=zeros(lw,1);
%进度条
h=waitbar(0,'开始计算','Position',[500 300 275 60],'Name','计算进度...');
% pause(1);
hac=get(get(h,'children'),'children');
hapa=findall(hac,'type','patch');
set(hapa,'EdgeColor','g','FaceColor','b');
task=0;
for a=1:lw
v=get(handles.Rad_Real,'Value');
if ~isequal(v,0) %判断实部虚部
f=@(x)cos(w(a).*x).*sinh(x)./(x-t);
else
f=@(x)sin(w(a).*x).*sinh(x)./(x-t);
end
% eval(['fun=@(x)',get(handles.f,'String'),';']);
for b=1:ln
task=task+100/12;
waitbar(task/100,h,['已完成' num2str(task) '%']);
Er(a,b)=I_ErSinh(f,w(a),n(b),t,tag);%计算误差
end
% [I_gk,Er_gk(a)]=quadgk(f,-1,1);
end
close(h);
%绘图
axes(handles.axes1);
legend off;
w=64;
if ~isequal(v,0) %判断实部虚部
f1=@(x)cos(w.*x).*sinh(x)./(x-t);
else
f1=@(x)sin(w.*x).*sinh(x)./(x-t);
end
legend off;
ezplot(f1,[-1,1]),legend('w=128'),grid on;
w=[16,32,64,128];
%计算Rate
Er(2,3)=Er(2,3);
Er(3,3)=Er(3,3);
Er(4,1)=Er(4,1);
Er(4,2)=Er(4,2);
Er(4,3)=Er(4,3);
Rate=log(Er(3,:)./Er(4,:))./log(2);
e=[Er;Rate];
c={ e(1,1),e(2,1),e(3,1),e(4,1),e(5,1);...
e(1,2),e(2,2),e(3,2),e(4,2),e(5,2);...
e(1,3),e(2,3),e(3,3),e(4,3),e(5,3)};
%设置表格
set(handles.Table,'RowName',{ num2str(w(1)), num2str(w(2)), num2str(w(3)),num2str(w(4)),'Rate'});
set(handles.Table,'ColumnName',{ num2str(n(1)), num2str(n(2)), num2str(n(3))});
set(handles.Table,'Data',c');
set(handles.Table,'UserData',c');
guidata(hObject, handles);
% --------------------------------------------------------------------
function Open_Callback(hObject, eventdata, handles)
% hObject handle to Open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
file = uigetfile('*.m');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function New_Callback(hObject, eventdata, handles)
% hObject handle to New (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Exit_Callback(hObject, eventdata, handles)
% hObject handle to Exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg('确定要返回主界面吗?','提示','Yes','No','Yes');
if strcmp(selection,'No')
return;
elseif strcmp(selection,'Yes')
clc,close;
end
function f_Callback(hObject, eventdata, handles)
% hObject handle to f (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of f as text
% str2double(get(hObject,'String')) returns contents of f as a double
% --- Executes during object creation, after setting all properties.
function f_CreateFcn(hObject, eventdata, handles)
% hObject handle to f (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function n_Callback(hObject, eventdata, handles)
% hObject handle to n (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of n as text
% str2double(get(hObject,'String')) returns contents of n as a double
% --- Executes during object creation, after setting all properties.
function n_CreateFcn(hObject, eventdata, handles)
% hObject handle to n (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function w_Callback(hObject, eventdata, handles)
% hObject handle to w (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of w as text
% str2double(get(hObject,'String')) returns contents of w as a double
% --- Executes during object creation, after setting all properties.
function w_CreateFcn(hObject, eventdata, handles)
% hObject handle to w (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% set(hObject,'String','OK');
if isempty(get(handles.w,'String')) %获取震荡速率w
msgbox(' 请输入 w 的值!','提示','help');
return;
else
w=str2num(get(handles.w,'String'));
end
if isempty(get(handles.t,'String')) %判断t是否为空
msgbox(' 请输入 t 的值!','提示','help');
return;
else
t=str2num(get(handles.t,'String'));
end
if isempty(get(handles.n,'String')) %获取n值
msgbox(' 请输入 n 的值!','提示','help');
return;
else
n=str2num(get(handles.n,'String'));
% if isnan(n) %判断是否是实数
% errodlg('必须输入整数!','Error','modal');
% return; %跳出一个对话框
% end
end
lw=length(w);
ln=length(n);
Er=zeros(lw,ln); %误差表
%进度条
h=waitbar(0,'开始计算','Position',[500 300 275 60],'Name','计算进度...');
% pause(1);
hac=get(get(h,'children'),'children');
hapa=findall(hac,'type','patch');
set(hapa,'EdgeColor','b','FaceColor','g');
task=0;
for a=1:lw
if isempty(get(handles.f,'String')) %获取n值
msgbox('请输入非振荡非奇异部分的函数f(x)!','提示','help');
return;
end
v=get(handles.Rad_Real,'Value');
if ~isequal(v,0) %判断实部虚部
eval(['fun=@(x)','cos(w(a).*x).*',get(handles.f,'String'),'./(x-t)',';']);
tag=1;
else
eval(['fun=@(x)','sin(w(a).*x).*',get(handles.f,'String'),'./(x-t)',';']);
tag=0;
end
eval(['f=@(x)',get(handles.f,'String'),';']);
for b=1:ln
task=task+100/12;
waitbar(task/100,h,['已完成' num2str(task) '%']);
Er(a,b)=I_Er(fun,f,w(a),n(b),t,tag,1);
end
end
close(h);
%绘图
axes(handles.axes1);
legend off;
ezplot(fun,[-1,1]),grid on;
%计算Rate
% Rate=log(Er(3,:)./Er(4,:))./log(2);
% e=[Er;Rate];
% c={ e(1,1),e(2,1),e(3,1),e(4,1),e(5,1);...
% e(1,2),e(2,2),e(3,2),e(4,2),e(5,2);...
% e(1,3),e(2,3),e(3,3),e(4,3),e(5,3)};
%设置表格
set(handles.Table,'RowName',{ num2str(w(1)), num2str(w(2)), num2str(w(3)),num2str(w(4))});
set(handles.Table,'ColumnName',{ num2str(n(1)), num2str(n(2)), num2str(n(3))});
set(handles.Table,'Data',Er);
set(handles.Table,'UserData',Er);
%%最速下降分析
% axes(handles.axes1);
% hold off;
% global Er;
% % set(0,'DefaultAxesColorOrder',[1 0 0;0 1 0;0 0 1]);
% % set(0,'DefaultAxesLineStyleOrder','-*|-^|-o');
% % for a=1:ln
% % str=strcat('n=',num2str(n(a)));
% % plot(w,log(Er(:,a)')),legend(str),hold all;
% % end
% % hold off;
% % set(0,'DefaultAxesLineStyleOrder','remove');
% % set(0,'DefaultAxesColorOrder','remove');
% plot(w,log(Er(:,1)'),'-*r'),hold on;
% plot(w,log(Er(:,2)'),'-^g'),hold on;
% plot(w,log(Er(:,3)'),'-ob'),hold on;
% legend('n=3','n=4','n=5');
guidata(hObject, handles);
% --- Executes on button press in Clear.
function Clear_Callback(hObject, eventdata, handles)
% hObject handle to Clear (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.f,'String','');
set(handles.t,'String','');
set(handles.w,'String','');
set(handles.n,'String','');
%清空表格
set(handles.Table,'Data',[]);
legend off;
cla;
guidata(hObject, handles);
% --- Executes on button press in Rad_Real.
function Rad_Real_Callback(hObject, eventdata, handles)
% hObject handle to Rad_Real (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.Rad_Real,'value',1);
set(handles.Rad_Img,'value',0);
% Hint: get(hObject,'Value') returns toggle state of Rad_Real
guidata(hObject, handles);
% --- Executes on button press in Rad_Img.
function Rad_Img_Callback(hObject, eventdata, handles)
% hObject handle to Rad_Img (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.Rad_Real,'value',0);
set(handles.Rad_Img,'value',1);
% Hint: get(hObject,'Value') returns toggle state of Rad_Img
guidata(hObject, handles);
function t_Callback(hObject, eventdata, handles)
% hObject handle to t (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of t as text
% str2double(get(hObject,'String')) returns contents of t as a double
% --- Executes during object creation, after setting all properties.
function t_CreateFcn(hObject, eventdata, handles)
% hObject handle to t (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function Def_Callback(hObject, eventdata, handles)
% hObject handle to Def (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.f,'String','');
set(handles.t,'String','0');
set(handles.w,'String','8,16,32,64');
set(handles.n,'String','3,4,5');
guidata(hObject, handles);
% --------------------------------------------------------------------
function Link_Callback(hObject, eventdata, handles)
% hObject handle to Link (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
first;
% --------------------------------------------------------------------
function Draw_Callback(hObject, eventdata, handles)
% hObject handle to Draw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Fresh_Callback(hObject, eventdata, handles)
% hObject handle to Fresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function chap1_Callback(hObject, eventdata, handles)
% hObject handle to chap1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function cmpEr_Callback(hObject, eventdata, handles)
% hObject handle to cmpEr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%第四章示例图
w=[16,32,64,128];
time=zeros(3,4);
Erquad=zeros(3,4);
x=-1:0.01:1;
for a=1:4
% f1=@(x)cos(w(a).*x).*exp(x)./(x-t);
str=strcat('w=',num2str(w(a)));
% f2=@(x)sin(w(a).*x).*sinh(x)./(x-t);
f3=@(x)sin(w(a).*x).*exp(x);
% subplot(2,2,a),plot(x,f3(x)),text(0.6,3.5,str),xlabel('x'),ylabel('被积函数值');
%精确值
I=integral(f3,-1,1,'AbsTol',1e-18,'RelTol',1e-18);
% tic;
% I_trapz=trapz(f3(x));
% time(1,a)=toc;
% Er(1,a)=abs(I_trapz-I);
tic;
I_quad=quad(f3,-1,1);
time(1,a)=toc;
Erquad(1,a)=abs(I_quad-I);
tic;
I_quadl=quadl(f3,-1,1);
time(2,a)=toc;
Erquad(2,a)=abs(I_quadl-I);
tic;
I_quadgk=quadgk(f3,-1,1);
time(3,a)=toc;
Erquad(3,a)=abs(I_quadgk-I);
end
set(handles.Table,'Data',Erquad'); %设置表格
set(handles.Table,'RowName',{ num2str(w(1)), num2str(w(2)), num2str(w(3)),num2str(w(4))});
set(handles.Table,'ColumnName',{ 'quad', 'quadl','quadgk'});
axes(handles.axes1);
% figure;
hold off;
plot(w,log(Erquad(1,:)),'-*r'),hold on;
plot(w,log(Erquad(2,:)),'-^g'),hold on;
plot(w,log(Erquad(3,:)),'-ob');
legend('quad','quadl','quadgk','location','northeast');
guidata(hObject, handles);
% --------------------------------------------------------------------
function cmpTime_Callback(hObject, eventdata, handles)
% hObject handle to cmpTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%第四章示例图
w=[16,32,64,128];
time=zeros(3,4);
Erquad=zeros(3,4);
for a=1:4
f3=@(x)sin(w(a).*x).*exp(x);
% subplot(2,2,a),plot(x,f3(x)),text(0.6,3.5,str),xlabel('x'),ylabel('被积函数值');
%精确值
I=integral(f3,-1,1,'AbsTol',1e-18,'RelTol',1e-18);
% tic;
% I_trapz=trapz(f3(x));
% time(1,a)=toc;
% Er(1,a)=abs(I_trapz-I);
tic;
I_quad=quad(f3,-1,1);
time(1,a)=toc;
Erquad(1,a)=abs(I_quad-I);
tic;
I_quadl=quadl(f3,-1,1);
time(2,a)=toc;
Erquad(2,a)=abs(I_quadl-I);
tic;
I_quadgk=quadgk(f3,-1,1);
time(3,a)=toc;
Erquad(3,a)=abs(I_quadgk-I);
end
set(handles.Table,'Data',time'); %设置表格
set(handles.Table,'RowName',{ num2str(w(1)), num2str(w(2)), num2str(w(3)),num2str(w(4))});
set(handles.Table,'ColumnName',{ 'quad', 'quadl','quadgk'});
axes(handles.axes1);
% figure;
hold off;
plot(w,time(1,:),'-*r'),hold on;
plot(w,time(2,:),'-^g'),hold on;
plot(w,time(3,:),'-ob');
% xlabel('w'),ylabel('计算时间(s)');
legend('quad','quadl','quadgk','location','northwest');
guidata(hObject, handles);
% --------------------------------------------------------------------
function Gredit_Callback(hObject, eventdata, handles)
% hObject handle to Gredit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(get(handles.w,'String')) %获取震荡速率w
msgbox(' 请输入 w 的值!','提示','help');
return;
else
w=str2num(get(handles.w,'String'));
end
if isempty(get(handles.t,'String')) %判断t是否为空
msgbox(' 请输入 t 的值!','提示','help');
return;
else
t=str2num(get(handles.t,'String'));
end
if isempty(get(handles.n,'String')) %获取n值
msgbox(' 请输入 n 的值!','提示','help');
return;
else
n=str2num(get(handles.n,'String'));
% if isnan(n) %判断是否是实数
% errodlg('必须输入整数!','Error','modal');
% return; %跳出一个对话框
% end
end
lw=length(w);
ln=length(n);
axes(handles.axes1);
% figure;
hold off;
global Er;
% global Er_gk;
% set(0,'DefaultAxesColorOrder',[1 0 0;0 1 0;0 0 1]);
% set(0,'DefaultAxesLineStyleOrder','-*|-^|-o');
% for a=1:ln
% str=strcat('n=',num2str(n(a)));
% plot(w,log(Er(:,a)')),legend(str),hold all;
% end
% hold off;
% set(0,'DefaultAxesLineStyleOrder','remove');
% set(0,'DefaultAxesColorOrder','remove');
plot(w,log(Er(:,1)'),'-*r'),hold on;
plot(w,log(Er(:,2)'),'-^g'),hold on;
plot(w,log(Er(:,3)'),'-ob'),hold on;
% plot(w,log(Er_gk),'p-c');
% legend('n=3','n=4','n=5','quadgk','location','best');
% xlabel('w'),ylabel('误差对数值log(Er)');
legend('n=3','n=4','n=5','location','best');
%计算Rate
Rate=log(Er(3,:)./Er(4,:))./log(2);
e=[Er;Rate];
c={ e(1,1),e(2,1),e(3,1),e(4,1),e(5,1);...
e(1,2),e(2,2),e(3,2),e(4,2),e(5,2);...
e(1,3),e(2,3),e(3,3),e(4,3),e(5,3)};
%设置表格
set(handles.Table,'RowName',{ num2str(w(1)), num2str(w(2)), num2str(w(3)),num2str(w(4)),'Rate'});
set(handles.Table,'ColumnName',{ num2str(n(1)), num2str(n(2)), num2str(n(3))});
set(handles.Table,'Data',c');
set(handles.Table,'UserData',c');
guidata(hObject, handles);
% --------------------------------------------------------------------
function chap1ex1_Callback(hObject, eventdata, handles)
% hObject handle to chap1ex1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%第一章示例图
w=[16,32,64,128];
t=-0.13;
x=-1:0.005:1;
figure;
for a=1:4
% f1=@(x)cos(w(a).*x).*exp(x)./(x-t);
str=strcat('w=',num2str(w(a)));
f2=@(x)sin(w(a).*x).*sinh(x)./(x-t);
% subplot(2,2,a),plot3(x,f1(x),f2(x));
subplot(2,2,a),plot(x,f2(x)),text(0.6,4,str),xlabel('x'),ylabel('一次被积函数值'),axis([-1 1 -5 5]);
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function chap1ex2_Callback(hObject, eventdata, handles)
% hObject handle to chap1ex2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%第一章示例图
w=[16,32,64,128];
t=-0.13;
x=-1:0.005:1;
figure;
for a=1:4
% f1=@(x)cos(w(a).*x).*exp(x)./(x-t);
str=strcat('w=',num2str(w(a)));
f2=@(x)sin(w(a).*x.*x).*sinh(x)./(x-t);
% subplot(2,2,a),plot3(x,f1(x),f2(x));
subplot(2,2,a),plot(x,f2(x)),text(0.6,4,str),xlabel('x'),ylabel('二次被积函数值'),axis([-1 1 -5 5]);
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function TraEr_Callback(hObject, eventdata, handles)
% hObject handle to TraEr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%第一章经典积分图
%进度条
h=waitbar(0,'开始计算','Position',[500 300 275 60],'Name','计算进度...');
% pause(1);
hac=get(get(h,'children'),'children');
hapa=findall(hac,'type','patch');
set(hapa,'EdgeColor','b','FaceColor','c');
task=0;
q_5=zeros(100,1);
q_10=zeros(100,1);
for w=1:100,
f=@(x)exp(x+1i*w*x);
q_5(w)=gausslegendre(f,-1,1,5);
q_10(w)=gausslegendre(f,-1,1,10);
task=task+1;
waitbar(task/100,h,['正在计算w=' num2str(w) ',已完成' num2str(task) '%']);
end;
close(h);
%精确值利用Mathematica计算,载入精确值
load('I_imag.mat');
load('I_real.mat');
Er_5=abs(q_5-I_imag.*1i-I_real);
Er_10=abs(q_10-I_imag.*1i-I_real);
figure;
w=1:100;
subplot(1,2,1),plot(w,Er_5(1:100,1),'b-'),xlabel('w'),ylabel('5点Gauss-legendre求积公式误差'),legend('n=5');
subplot(1,2,2),plot(w,Er_10(1:100,1),'r-'),xlabel('w'),ylabel('10点Gauss-legendre求积公式误差'),legend('n=10');