Undefined function '...' for input arguments of type 'double' error AND error in function?
Show older comments
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))]
Accepted Answer
More Answers (1)
brijendra yadav
on 14 Apr 2017
Edited: per isakson
on 14 Apr 2017
[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);
Categories
Find more on Debugging and Analysis 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!