Need assistance implementing ode45 in GUI
1 次查看(过去 30 天)
显示 更早的评论
Hey not sure what to do about the errors I'm getting any assistance is greatly appreciated
My code:
function varargout = GUI_Assignment_Zuhs_Carey_Otic(varargin)
% GUI_ASSIGNMENT_ZUHS_CAREY_OTIC MATLAB code for GUI_Assignment_Zuhs_Carey_Otic.fig
% GUI_ASSIGNMENT_ZUHS_CAREY_OTIC, by itself, creates a new GUI_ASSIGNMENT_ZUHS_CAREY_OTIC or raises the existing
% singleton*.
%
% H = GUI_ASSIGNMENT_ZUHS_CAREY_OTIC returns the handle to a new GUI_ASSIGNMENT_ZUHS_CAREY_OTIC or the handle to
% the existing singleton*.
%
% GUI_ASSIGNMENT_ZUHS_CAREY_OTIC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_ASSIGNMENT_ZUHS_CAREY_OTIC.M with the given input arguments.
%
% GUI_ASSIGNMENT_ZUHS_CAREY_OTIC('Property','Value',...) creates a new GUI_ASSIGNMENT_ZUHS_CAREY_OTIC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_Assignment_Zuhs_Carey_Otic_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_Assignment_Zuhs_Carey_Otic_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 GUI_Assignment_Zuhs_Carey_Otic
% Last Modified by GUIDE v2.5 25-Apr-2018 19:32:31
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_Assignment_Zuhs_Carey_Otic_OpeningFcn, ...
'gui_OutputFcn', @GUI_Assignment_Zuhs_Carey_Otic_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 GUI_Assignment_Zuhs_Carey_Otic is made visible.
function GUI_Assignment_Zuhs_Carey_Otic_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 GUI_Assignment_Zuhs_Carey_Otic (see VARARGIN)
% Choose default command line output for GUI_Assignment_Zuhs_Carey_Otic
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI_Assignment_Zuhs_Carey_Otic wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_Assignment_Zuhs_Carey_Otic_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 Avalue_Callback(hObject, eventdata, handles)
% hObject handle to Avalue (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 Avalue as text
% str2double(get(hObject,'String')) returns contents of Avalue as a double
% --- Executes during object creation, after setting all properties.
function Avalue_CreateFcn(hObject, eventdata, handles)
% hObject handle to Avalue (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 Bvalue_Callback(hObject, eventdata, handles)
% hObject handle to Bvalue (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 Bvalue as text
% str2double(get(hObject,'String')) returns contents of Bvalue as a double
% --- Executes during object creation, after setting all properties.
function Bvalue_CreateFcn(hObject, eventdata, handles)
% hObject handle to Bvalue (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 Cvalue_Callback(hObject, eventdata, handles)
% hObject handle to Cvalue (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 Cvalue as text
% str2double(get(hObject,'String')) returns contents of Cvalue as a double
% --- Executes during object creation, after setting all properties.
function Cvalue_CreateFcn(hObject, eventdata, handles)
% hObject handle to Cvalue (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 Dvalue_Callback(hObject, eventdata, handles)
% hObject handle to Dvalue (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 Dvalue as text
% str2double(get(hObject,'String')) returns contents of Dvalue as a double
% --- Executes during object creation, after setting all properties.
function Dvalue_CreateFcn(hObject, eventdata, handles)
% hObject handle to Dvalue (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 Evalue_Callback(hObject, eventdata, handles)
% hObject handle to Evalue (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 Evalue as text
% str2double(get(hObject,'String')) returns contents of Evalue as a double
% --- Executes during object creation, after setting all properties.
function Evalue_CreateFcn(hObject, eventdata, handles)
% hObject handle to Evalue (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 Fvalue_Callback(hObject, eventdata, handles)
% hObject handle to Fvalue (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 Fvalue as text
% str2double(get(hObject,'String')) returns contents of Fvalue as a double
% --- Executes during object creation, after setting all properties.
function Fvalue_CreateFcn(hObject, eventdata, handles)
% hObject handle to Fvalue (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 tvalue_Callback(hObject, eventdata, handles)
% hObject handle to tvalue (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 tvalue as text
% str2double(get(hObject,'String')) returns contents of tvalue as a double
% --- Executes during object creation, after setting all properties.
function tvalue_CreateFcn(hObject, eventdata, handles)
% hObject handle to tvalue (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 Runbutton.
function Runbutton_Callback(hObject, eventdata, handles)
% hObject handle to Runbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
A=str2double(get(handles.Avalue, 'string'));
B=str2double(get(handles.Bvalue, 'string'));
C=str2double(get(handles.Cvalue, 'string'));
E=str2double(get(handles.Evalue, 'string'));
F=str2double(get(handles.Fvalue, 'string'));
tmax=str2double(get(handles.tvalue, 'string'));
output=func(A,B,C,E,F,tmax)
ydot=funct(t,Y)
plot(t, y(:,1), 'Parent', handles.axes1)
grid on
plot(t, y(:,2), 'Parent', handles.axes2)
plot(t, y(:,3), 'Parent', handles.axes3)
plot3(y(:,1),y(:,2),y(:,3), 'Parent', handles.axes4)
function output=func(A,B,C,E,F,tmax)
[t,y]=ode45(@funct,[0 tmax],[0 0 0]);
function ydot=funct(t,y)
F2=F;
B2=B;
C2=C;
E2=E;
A2=A;
ydot(1)=y(2);
ydot(2)=y(3);
ydot(3)=((F2*exp(-0.1*t)*cos(t))+(B2*y(3))-(C2*t*y(2))+(E2*y(1)))/A2;
ydot=ydot';
Here are my errors:
>> GUI_Assignment_Zuhs_Carey_Otic
Undefined function or variable 'F'.
Error in GUI_Assignment_Zuhs_Carey_Otic>funct (line 262)
F2=F;
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in GUI_Assignment_Zuhs_Carey_Otic>func (line 260)
[t,y]=ode45(@funct,[0 tmax],[0 0 0]);
Error in GUI_Assignment_Zuhs_Carey_Otic>Runbutton_Callback (line 251)
output=func(A,B,C,E,F,tmax)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI_Assignment_Zuhs_Carey_Otic (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUI_Assignment_Zuhs_Carey_Otic('Runbutton_Callback',
hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
0 个评论
回答(1 个)
Walter Roberson
2018-4-26
Your funct() is not nested in your func(), so they do not share variables. You should have parameterized like I said before. http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
[t, y] = ode45(@(t,y) funct(t, y, A, B, C, E, F), [0 tmax], [0 0 0]);
with
function ydot = funct(t, y, A, B, C, E, F)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!