⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nu.m

📁 This GUI can be used by entering nu at the MATLAB command prompt. The user can either select a funct
💻 M
📖 第 1 页 / 共 2 页
字号:
%Associated M-file for numerical integration GUI by Robert Ackford%        %Last updated 25/04/05. E-mail; RobertAckuk@yahoo.com%function varargout = nu(varargin)% NU Application M-file for nu.fig%    FIG = NU launch nu GUI.%    NU('callback_name', ...) invoke the named callback.% Last Modified by GUIDE v2.5 25-Apr-2005 16:10:17if nargin == 0  % LAUNCH GUI	fig = openfig(mfilename,'reuse');	% Use system color scheme for figure:	set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));	% Generate a structure of handles to pass to callbacks, and store it. 	handles = guihandles(fig);	guidata(fig, handles);	if nargout > 0		varargout{1} = fig;	endelseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK	try		[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard	catch		disp(lasterr);	endend%| ABOUT CALLBACKS:%| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism.%|%| Each callback subfunction declaration has the following form:%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)%|%| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback',%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.%|%| H is the callback object's handle (obtained using GCBO).%|%| EVENTDATA is empty, but reserved for future use.%|%| HANDLES is a structure containing handles of components in GUI using%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This%| structure is created at GUI startup using GUIHANDLES and stored in%| the figure's application data using GUIDATA. A copy of the structure%| is passed to each callback.  You can store additional information in%| this structure at GUI startup, and you can change the structure%| during callbacks.  Call guidata(h, handles) after changing your%| copy to replace the stored original so that subsequent callbacks see%| the updates. Type "help guihandles" and "help guidata" for more%| information.%|%| VARARGIN contains any extra arguments you have passed to the%| callback. Specify the extra arguments by editing the callback%| property in the inspector. By default, GUIDE sets the property to:%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))%| Add any extra arguments after the last argument, before the final%| closing parenthesis.% --------------------------------------------------------------------function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.pushbutton1.s1=str2num(get(handles.s1,'string'));s2=str2num(get(handles.s2,'string'));r1=str2num(get(handles.R1,'string'));r2=str2num(get(handles.R2,'string'));x=r1:0.001:r2;y=eval(get(handles.func,'string'));ma = max(y);mi = -min(y);plot(x,y);grid on;set(handles.maxlab,'visible','On');    set(handles.max,'visible','On');    if ma >= miset(handles.max,'string',num2str(ma));else if mi > ma       set(handles.max,'string',num2str(mi));   endend% --------------------------------------------------------------------function varargout = func_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.func.PLOTGUI('func_Callback',gcbo,[],guidata(gcbo))% --------------------------------------------------------------------function varargout = method_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.method.val = get(handles.method,'Value'); % Callback enables edit text box for use with Gaussian quadrature%switch valcase 1     set(handles.ordlab,'visible','Off');    set(handles.Ordernumber,'visible','Off');case 2    set(handles.ordlab,'visible','Off');    set(handles.Ordernumber,'visible','Off');case 3    set(handles.ordlab,'visible','On');    set(handles.Ordernumber,'visible','On');end% --------------------------------------------------------------------function varargout = number_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.number.disp('number Callback not implemented yet.')% --------------------------------------------------------------------function varargout = ans_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.ans.disp('ans Callback not implemented yet.')% --- Executes on button press in integral.function integral_Callback(hObject, eventdata, handles)% hObject    handle to integral (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)a=str2num(get(handles.xfrom,'string'));b=str2num(get(handles.xto,'string'));n=str2num(get(handles.number,'string'));s1=str2num(get(handles.s1,'string'));s2=str2num(get(handles.s2,'string'));val = get(handles.method,'Value');switch valcase 1            num=n+1;            h=(b-a)/(num-1);            x=a:h:b;            y=eval(get(handles.func,'string'));            I=h*(0.5*y(1)+sum(y(2:num-1))+0.5*y(num));            format long g;            set(handles.ans,'string',num2str(I));case 2            num=2*n+1;            h=(b-a)/(num-1);            x=a:h:b;            y=eval(get(handles.func,'string'));                        I=(h/3)*(y(1)+4*sum(y(2:2:num-1))+2*sum(y(3:2:num-2))+y(num));            format long g;            set(handles.ans,'string',num2str(I));case 3                            ord=str2num(get(handles.Ordernumber,'string'));      %compute nodes and weights, function from%            %Numerical Methods with Matlab:Gerald Recktenwald,2000, Prentice Hall%            [z,wt] = GLNodeWt(ord);                                                H = (b-a)/n;            H2 = H/2;           %Avoids repeated computation of H/2%            xb = a:H:b;                                 I = 0;                        for i=1 : n  %Loop for the panels%                               x= (0.5*(xb(i)+xb(i+1)))+H2*z; %Adjust the nodes%                y=eval(get(handles.func,'string')); %Evaluate adjusted f(x)%                I=I + sum(wt.*y)    %find initial integral vector%            end         I= I*H2       %Sum Integral%         format long g;          set(handles.ans,'string',num2str(I));             end                      % --- Executes during object creation, after setting all properties.function method_CreateFcn(hObject, eventdata, handles)% hObject    handle to method (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- Executes during object creation, after setting all properties.function Ordernumber_CreateFcn(hObject, eventdata, handles)% hObject    handle to Ordernumber (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction Ordernumber_Callback(hObject, eventdata, handles)% hObject    handle to Ordernumber (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 Ordernumber as text%        str2double(get(hObject,'String')) returns contents of Ordernumber as a double% --- If Enable == 'on', executes on mouse press in 5 pixel border.% --- Otherwise, executes on mouse press in 5 pixel border or over method.function method_ButtonDownFcn(hObject, eventdata, handles)% hObject    handle to method (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)val = get(handles.method,'Value');switch valcase 1disp('Trapezium rule used');case 2disp('Simpsons rule used');    case 3    set(handles.Ordernumber,'visible',on);end% --------------------------------------------------------------------function varargout = max_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.max.disp('max Callback not implemented yet.')% --- Executes on button press in stat.function stat_Callback(hObject, eventdata, handles)% hObject    handle to stat (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hint: get(hObject,'Value') returns toggle state of stat

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -