Undefined function '...' for input arguments of type 'double' error AND error in function?
Afficher commentaires plus anciens
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 commentaires
per isakson
le 14 Nov 2016
Run
which Fexample1
and show us the output
d b
le 14 Nov 2016
Réponse acceptée
Plus de réponses (1)
brijendra yadav
le 14 Avr 2017
Modifié(e) : per isakson
le 14 Avr 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);
Catégories
En savoir plus sur Debugging and Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!