Not enough input arguments

7 visualizaciones (últimos 30 días)
Ricardo Gasque Ruiz
Ricardo Gasque Ruiz el 29 de Nov. de 2020
Comentada: Walter Roberson el 30 de Nov. de 2020
Hi i have a problem with my code and i do not know how to solve it it says that there is not enough input arguments.
Its say the problem is on line 2
function [x,y,z]=Fun_RungK4(f,g,j,x0,y0,z0,a,b,h)
t = a:h:b;
n = length(t);
x = [x0];
y = [y0];
z = [z0];
for i=1:n-1
k1 = h * f(x(i), y(i), z(i), t(i));
l1 = h * g(x(i), y(i), z(i), t(i));
m1 = h * j(x(i), y(i), z(i), t(i));
k2 = h * f(x(i) + (k1/2), y(i) + (l1/2), z(i) + (m1/2), t(i) + (h/2));
l2 = h * g(x(i) + (k1/2), y(i) + (l1/2), z(i) + (m1/2), t(i) + (h/2));
m2 = h * j(x(i) + (k1/2), y(i) + (l1/2), z(i) + (m1/2), t(i) + (h/2));
k3 = h * f(x(i) + (k2/2), y(i) + (l2/2), z(i) + (m2/2), t(i) + (h/2));
l3 = h * g(x(i) + (k2/2), y(i) + (l2/2), z(i) + (m2/2), t(i) + (h/2));
m3 = h * j(x(i) + (k2/2), y(i) + (l2/2), z(i) + (m2/2), t(i) + (h/2));
k4 = h * f(x(i) + k3, y(i) + l3, z(i) + m3, t(i) + h);
l4 = h * g(x(i) + k3, y(i) + l3, z(i) + m3, t(i) + h);
m4 = h * j(x(i) + k3, y(i) + l3, z(i) + m3, t(i) + h);
x(i + 1) = x(i) + ((h/6) * (k1 + (2*k2) + (2*k3) + k4));
y(i + 1) = y(i) + ((h/6) * (l1 + (2*l2) + (2*l3) + l4));
z(i + 1) = z(i) + ((h/6) * (m1 + (2*m2) + (2*m3) + m4));
end
plot3(t,x,t,y,t,z,'-g')
comet3(x,y,x)
end
  3 comentarios
Ricardo Gasque Ruiz
Ricardo Gasque Ruiz el 30 de Nov. de 2020
Here is the other part
clc
clear;
alpha = 0.038955; %a
beta = 0.017614; %b
gamma = 0.001991; %c
delta = 0.000901; %d
epsilon = -0.1434; %e
theta = 0.0813; %f
lambda = 0.0416; %g
a = 0;
b = 200;
h= 1;
x0 = 60.275818;
y0 = 2.043051;
z0 = 0.033794;
f = @(x,y,z) (alpha*x) - (beta*x*y) %función
g = @(x,y,z)-(gamma*x)+(delta*x*y)-(epsilon*y*z)
j = @(x,y,z)-(theta*z)+(lambda*y*z)
[x,y,z]=Fun_RungK4(f,g,j,x0,y0,z0,a,h,b);
xlabel('Eje x')
ylabel('Eje y')
zlabel('Eje z')
Walter Roberson
Walter Roberson el 30 de Nov. de 2020
This creates function handles that expect three parameters, but the code passes four parameters to them.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Nov. de 2020
You have not shown us the definition of f, g, or j, so we cannot say which of them needs more than the four input arguments you are passing to them.
That said... 95% of the time when someone posts something like this, it is because they have pressed the big green Run button to run the code, instead of going down to the command line and invoking the code passing in parameters.
If you press the big green Run button, MATLAB will not look inside the base workspace to find definitions for f, g, j, x0, y0, z0, a, b, or h: MATLAB relies strictly on the values passed in positionally.
  1 comentario
Ricardo Gasque Ruiz
Ricardo Gasque Ruiz el 30 de Nov. de 2020
yes I did press de big green buttom. How do I invoke the code passing in parameters?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by