error using ode45 in gui
Show older comments
while debugging code for flat-fire using ode45 it gives error
err0r:-
??? Error while evaluating uicontrol Callback
??? Error using ==> feval
Undefined function or method 'fnflatfiredragwind' for input
arguments of type 'double'.
Error in ==> guitry>togglebutton1_Callback at 187
[t,c,te,ze,ie] =
ode45('fnflatfiredragwind',tspan,c0,options,w1,w2,w3,k);
??? Error while evaluating uicontrol Callback
*
here is the function defined in toggle button
function togglebutton1_Callback(hObject, eventdata, handles)
v0 = str2num(get(handles.edit1,'string'));
theta = str2num(get(handles.edit2,'string'));
theta = theta*pi/180;
w1 = str2num(get(handles.edit3,'string'));
w2 = str2num(get(handles.edit4,'string'));
w3 = str2num(get(handles.edit5,'string'));
k = str2num(get(handles.edit6,'string'));
set(handles.text1,'string',result);
c0 = [0;v0*cos(theta);0;v0*sin(theta);0;0];
options = odeset('events','on');
tspan = [0 10];
[t,c,te,ze,ie] = ode45('fnflatfiredragwind',tspan,c0,options,w1,w2,w3,k);
what is this error ????????????????
please help me for this
thanks
pawan kumar
1 Comment
Jan
on 28 Sep 2011
Please use proper code formatting to improve the readability. Follow the "Markup help" link to learn the details.
Answers (4)
Grzegorz Knor
on 28 Sep 2011
Replace line:
[t,c,te,ze,ie] = ode45('fnflatfiredragwind',tspan,c0,options,w1,w2,w3,k);
with:
[t,c,te,ze,ie] = ode45(@fnflatfiredragwind,tspan,c0,options,w1,w2,w3,k);
5 Comments
Jan
on 28 Sep 2011
Why? ODE45 can handle functions as names, as long as they are found in the path. But I would prefer a function handle also.
Grzegorz Knor
on 28 Sep 2011
Compare these examples:
function test
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
ode45(@rigid,[0 12],[0 1 1],options)
function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
And
function test
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
ode45('rigid',[0 12],[0 1 1],options)
function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
Walter Roberson
on 28 Sep 2011
When you pass a name as a function, the name will be evaluated in the base workspace to find the function. If the function is local to the file you invoked ode45 from, then it will not be known in the base workspace. Using function handles rather than function names solves this problem.
pawan kumar
on 29 Sep 2011
Grzegorz Knor
on 29 Sep 2011
You don't pass the k argument to the function. Please correct this line:
function [value,isterminal,dircn] = fnflatfiredragwind(t,c,flag,w1,w2,w3,k)
Jan
on 28 Sep 2011
0 votes
The error means, that the file "fnflatfiredragwind.m" cannot be found in the Matlab path and the current directory (see cd). Where is it? Is it a local subfunction? Then Grzegorz's idea of using a function handle might help.
Walter Roberson
on 29 Sep 2011
Convert
[t,c,te,ze,ie] =
ode45(@fnflatfiredragwind,tspan,c0,options,w1,w2,w3,k);
to
[t,c,te,ze,ie] =
ode45(@(t) fnflatfiredragwind(t,w1,w2,w3,k),tspan,c0,options);
convert
function [value,isterminal,dircn] = fnflatfiredragwind(t,c,flag,w1,w2,w3)
to
function [value,isterminal,dircn] = fnflatfiredragwind(t,c,flag,w1,w2,w3,k)
2 Comments
pawan kumar
on 4 Oct 2011
Walter Roberson
on 4 Oct 2011
Correction:
[t,c,te,ze,ie] =
ode45(@(t) fnflatfiredragwind(t,w1,w2,w3,k),tspan,c0,options);
should be
[t,c,te,ze,ie] =
ode45(@(t,c) fnflatfiredragwind(t,c,[],w1,w2,w3,k),tspan,c0,options);
pawan kumar
on 10 Oct 2011
0 votes
2 Comments
Walter Roberson
on 10 Oct 2011
Any program that has "clear all" in it is 99%+ likely to be broken.
Walter Roberson
on 10 Oct 2011
Please point me to a reference page or user guide page that shows passing additional variables by placing them after the "options" structure in an ode*() call. I have been unable to find such a page myself; all I have been able to find so far is pages that say specifically that YOU CANNOT DO THAT.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!