Not enough input arguments

2 views (last 30 days)
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 Comments
Ricardo Gasque Ruiz
Ricardo Gasque Ruiz on 30 Nov 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 on 30 Nov 2020
This creates function handles that expect three parameters, but the code passes four parameters to them.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Nov 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 Comment
Ricardo Gasque Ruiz
Ricardo Gasque Ruiz on 30 Nov 2020
yes I did press de big green buttom. How do I invoke the code passing in parameters?

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!