Undefined function '...' for input arguments of type 'double' error AND error in function?

Using MATLAB R2016b, I'm trying to evaluate a 2nd order ODE with Euler's method in MATLAB inputting a system of 1st order ODEs. I've already verified that all my scripts are in the directory specifed by 'pwd' [which seems to be a remedy for the 'undefined function'], but still get the undefined function '...' for input arguments of type 'double' error and the function error. All help is much appreciated:
Error using feval
Undefined function 'Fexample1' for input arguments of type 'double'.
Error in euler (line 39)
y(i,:) = y(i-1,:) + h*feval(F,t(i-1),y(i-1,:));
For the following code:
function [y,t] = euler(F,y0,a,b,m)
if nargin < 4, a = 0; b = 1; end
if nargin < 3, a = 0; b = 1; end
if nargin < 2, error('invalid number of inputs'); end
t = linspace(a,b,m)';
h = t(2)-t(1);
n = length(y0);
y = zeros(m,n);
y(1,:) = y0;
for i=2:m
y(i,:) = y(i-1,:) + h*feval(F,t(i-1),y(i-1,:));
end
In a separate .m file in the same directory I have:
function F = Fexample1(t,y)
F1 = y(2);
F2 = e.^(-t)*sin(t)-2*y(2)-2*y(1);
F = [F1,F2];
And in a third .m file in the same directory as the two above, I have:
[Y,t] = euler('Fexample1',[0 0],0,1,11);
Ye = [(1./2).*e.^(-t).*(sin(t)-t.*cos(t)) (1./2).*e.^(-t).*((t-1).*sin(t)-t.*cos(t))]

2 件のコメント

Run
which Fexample1
and show us the output
d b
d b 2016 年 11 月 14 日
Thanks for the response. I ran that in the Command Window and:
>> which Fexample1
'Fexample1' not found.

サインインしてコメントする。

 採用された回答

Jan
Jan 2016 年 11 月 14 日
The two statements:
I've already verified that all my scripts are in the directory specifed by 'pwd'
and
>> which Fexample1
'Fexample1' not found.
are a contradiction. Either the current folder is changed by a timer or GUI callback unexpectedly, or you've saved the file with a "l" (lowercase L) instead of "1".
Add the folder to the path (see addpath) instead of relying on it to be the current folder. Use function handles instead of strings to specifiy a function to be feval'ed.

その他の回答 (1 件)

brijendra yadav
brijendra yadav 2017 年 4 月 14 日
編集済み: per isakson 2017 年 4 月 14 日
[y, fs, bt]=wavread('sp29.wav');
y1=y(1001:2480);
y2=y(3001:4980);
y1=20*log10(abs(mtlb_fft(y1,1048)));
y2=20*log10(abs(mtlb_fft(y1,1048)));
x1=([1:length(y1)]/8000)*0100;
x2=[1:2048]*(8000/1048);
figure;subplot(3,2,1);plot(x1,y1);

カテゴリ

ヘルプ センター および File ExchangeDebugging and Analysis についてさらに検索

タグ

質問済み:

d b
2016 年 11 月 13 日

編集済み:

2017 年 4 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by