Error RungeKutta method......not enough input arguments
Mostrar comentarios más antiguos
function [xSol,ySol] = runKut4(dEqs,x,y,xStop,h)
%function [xSol,ySol] = runKut4(dEqs,x,y,xStop,h)
% 4th-order Runge--Kutta integration.
% USAGE: [xSol,ySol] = runKut4(dEqs,x,y,xStop,h)
% INPUT:
% dEqs = handle of function that specifies the 1st-order differential equations
% F(x,y) = [dy1/dx dy2/dx dy3/dx ...].
% x,y = initial values; y must be row vector.
% xStop = terminal value of x.
% h = increment of x used in integration.
% OUTPUT:
% xSol = x-values at which solution is computed.
% ySol = values of y corresponding to the x-values.
if size(y,1) > 1;
y = y';
end % y must be row vector
xSol = zeros(2,1);
ySol = zeros(2,length(y));
xSol(1)= x;
ySol(1,:)=y;
i = 1;
while x < xStop
i = i + 1;
h = min(h,xStop - x);
K1 = h*feval(dEqs,x,y);
K2 = h*feval(dEqs,x + h/2,y + K1/2);
K3 = h*feval(dEqs,x + h/2,y + K2/2);
K4 = h*feval(dEqs,x+h,y + K3);
y = y + (K1 + 2*K2 + 2*K3 + K4)/6;
x = x + h;
xSol(i) = x;
ySol(i,:) = y; % Store current soln.
end
-------------------------------------------------------------------------
function F = fex7_4(x,y)
% Differential. eqs. used in Example 7.4
F = zeros(1,2);
F(1) = y(2); F(2) = -0.1*y(2) - x;
[x,y] = runKut4(@fex7_4,0,[0 1],2,0.25);
printSol(x,y,1)
--------------------------------------------------------------
>> fex7_4 Error using fex7_4 (line 4) Not enough input arguments.
not enough input arguments ??????
3 comentarios
James Tursa
el 10 de Nov. de 2017
Please show us exactly how you are calling your function (i.e., give us the inputs), and then copy & paste the entire error message for us to see.
Camilo Sánchez
el 10 de Nov. de 2017
Camilo Sánchez
el 10 de Nov. de 2017
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!