MATLAB Answers

WHY do I get this error

105 ビュー (過去 30 日間)
mahesh tom
mahesh tom 2017 年 11 月 17 日
Edited: mahesh tom 2017 年 11 月 17 日
function dydt = free25(t,y);
g = 9.81;
l = 1;
dydt = [y(2);-g/l.*sin(y(1))];
end
[t,y]= ode45('free25',[0 10],[0 0.09]);%I typed this in command window
plot(t,y(:,1));
refline([0 0]);
Error using feval Undefined function 'free25' for input arguments of type 'double'.
Error in odearguments (line 87) 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);

  0 件のコメント

サインイン to comment.

採用された回答

Mischa Kim
Mischa Kim 2017 年 11 月 17 日
編集済み: Mischa Kim 2017 年 11 月 17 日
mahesh, is the above code all in one and the same script? If it is modify like this:
[t,y]= ode45(@free25,[0 10],[0 0.09]);%I typed this in command window
plot(t,y(:,1))
function dydt = free25(t,y)
g = 9.81;
l = 1;
dydt = [y(2);-g/l.*sin(y(1))];
end
Another option would be to store the first part of the script (first two commands) in one function and the second part in a different function. For this second option make sure you name the file the same way you name the function: free25.m

  3 件のコメント

mahesh tom
mahesh tom 2017 年 11 月 17 日
no..i have saved free25 as a separate .m file
Mischa Kim
Mischa Kim 2017 年 11 月 17 日
OK. Name of the file needs to be free25.m. In the command window type
[t,y] = ode45(@free25,[0 10],[0 0.09]);%I typed this in command window
and make sure the file is in the current folder (see folder window in MATLAB) or on in a folder that is in the MATLAB search path.
mahesh tom
mahesh tom 2017 年 11 月 17 日
Thank you! The problem was that the file was not on the MATLAB search path!

サインイン to comment.

More Answers (0)

サインイン してこの質問に回答します。

タグ


Translated by