Not enough input arguments
Show older comments
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
Answers (1)
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
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!