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

How did you call it? For example:
f = 1;
g = 1;
j = 1;
x0 = 1;
y0 = 1;
z0 = 1;
a = 1;
b = 1;
h = 5;
[x,y,z]=Fun_RungK4(f,g,j,x0,y0,z0,a,b,h)
You forgot to show us how you called the function. According to the error message you are not passing in all 9 arguments. You didn't just click the green run triangle without defining the input arguments did you?
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일

0 개 추천

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개)

카테고리

도움말 센터File 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