Not enough input arguments

Hi everybody, I am new to Matlab. I try running this example but I seem to run a problem that says not enough input arguments. here is the code. Anyone pls tell me which one I need to change to implement this. Thanks!
function J = cost_function(u)
u0 = u(1);
u1 = u(2);
u2 = u(3);
u3 = u(4);
u4 = u(5);
c = [1 0];
z1 = [0 0.4;-3.92 1.2];
z2 = [0;0.2];
x0 = [0;0];
x1 = z1*x0 + z2*u0;
x2 = z1^2*x0 + z1*z2*u0 + z2*u1;
x3 = z1^3*x0 + z1^2*z2*u0 + z1*z2*u1 + z2*u2;
x4 = z1^4*x0 + z1^3*z2*u0 + z1^2*z2*u1 + z1*z2*u2 + z2*u3;
x5 = z1^5*x0 + z1^4*z2*u0 + z1^3*z2*u1 + z1^2*z2*u2 + z1*z2*u3 + z2*u4;
J = (0.1-c*x0)^2 + (0.1-c*x1)^2 + (0.1-c*x2)^2 + (0.1-c*x3)^2 + (0.1-c*x4)^2

답변 (1개)

Thomas
Thomas 2014년 3월 6일
편집: Thomas 2014년 3월 6일

0 개 추천

Are you giving it u as an array? try running it like this.. works fine..
u=1:5;
cost_function(u)
output is
J =
0.14827
ans =
0.14827

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2014년 3월 6일

편집:

2014년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by