Problem 3: Create a graphical user interface GUI that allows the user to enter d
ID: 644062 • Letter: P
Question
Problem 3: Create a graphical user interface GUI that allows the user to enter dx, refinement and precision via text fields, and then plots the approximation results over 1x. Please name your user interface integralGul. Problem 2: Write a function called approximatelntegral that uses a ioop to compute a numerical approximation that adaptively changes Xx to smaller and smaller step sizes, until the approximation is accurate and precise within the number of decimal points defined by precision (difference between approxi+i and approxi must be less than 1 X 10^-precision). For example, you may test your function by assuming a starting value of triangle x = 1 and decrease the step size from there for each refinement step. I.e. the value for refinement may be 1/10th asking you to decrease Xx by this factor for each iteration step. Show the results of your refinement in tabular form (you may use fprintf), by displaying triangle x and the corresponding numerical approximation to the integral in the command window. The function should also return the content of this table in matrix form. I.e. a matrix containing the current triangle x and the numerical approximation to the integral (res = [dxi; approxi]). function res = approximatelntegral(dx, refinement, precision) Notes: 1. Assume dx is less than or equal to 1. 2. Assume refinement is less than or equal to dx. 3. Assume precision is an integer. 4. You do not need additional conditional statements testing the validity of the input arguments. Given the following integral and its numerical approximation:Explanation / Answer
function varargout = Gui4(varargin)
% GUI4 Application M-file for Gui4.fig
% GUI4, by itself, creates a new GUI4 or raises the existing
% singleton*.
%
% H = GUI4 returns the handle to a new GUI4 or the handle to
% the existing singleton*.
%
% GUI4('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI4.M with the given input arguments.
%
% GUI4('Property','Value',...) creates a new GUI4 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before two_axes_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Gui4_OpeningFcn via varargin.
%
% *See GUI Options - GUI allows only one instance to run (singleton).
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Gui4
% Copyright 2001-2006 The MathWorks, Inc.
% Last Modified by GUIDE v2.5 12-Mar-2015 01:16:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gui4_OpeningFcn, ...
'gui_OutputFcn', @Gui4_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 Gui4 is made visible.
function Gui4_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 Gui4 (see VARARGIN)
% Choose default command line output for Gui4
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Gui4 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gui4_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 plot_button_Callback(hObject, eventdata, handles, varargin)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get user input from GUI
dx = str2double(get(handles.f1_input,'String'));
refinement = str2double(get(handles.f2_input,'String'));
precision = eval(get(handles.t_input,'String'));
% Calculate data
res = approximateIntegral( dx,refinement,precision );
% Create frequency plot in proper axes
plot(handles.frequency_axes,res(:,1),res(:,1))
set(handles.frequency_axes,'XMinorTick','on')
grid on
function f1_input_Callback(hObject, eventdata, handles)
% hObject handle to f1_input (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 f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f1 field converts to a real number
f1 = str2double(get(hObject,'String'));
function f2_input_Callback(hObject, eventdata, handles)
% hObject handle to f2_input (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 f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f2 field converts to a real number
f2 = str2double(get(hObject,'String'));
function t_input_Callback(hObject, eventdata, handles)
% hObject handle to t_input (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_input as text
% str2double(get(hObject,'String')) returns contents of t_input
% as a double
% Test that the time vector is not too large, is not scalar,
% and increases monotonically. First fail if EVAL cannot parse it.
% --- Executes on key press with focus on plot_button and none of its controls.
function plot_button_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to plot_button (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function f2_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to f2_input (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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.