Not enough input arguments

7 次查看(过去 30 天)
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 个评论
Ricardo Gasque Ruiz
Ricardo Gasque Ruiz 2020-11-30
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 2020-11-30
This creates function handles that expect three parameters, but the code passes four parameters to them.

请先登录,再进行评论。

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by