Hi everyone! I'm writing a code of a constraint for the fmincon function but i don't understand what i'm doing wrong with the index. This is my code:
-lcon.m
function [c,ceq] = lcon(u, x_i, y_i, theta_i, x_f, y_f, theta_f, alphamin, alphamax)c = zeros([51*2, 1]) for (s=0:0.02:1) k_i = u(1) k_f = u(2) c((2*s/0.02+1)) = alphamax * ((9*s^4*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))^2 + 4*s^2*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i))^2 + k_i^2*cos(theta_i)^2 + k_i^2*sin(theta_i)^2 + 9*s^4*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))^2 + 4*s^2*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))^2 - 12*s^3*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)) - 12*s^3*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) - 4*k_i*s*cos(theta_i)*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) - 4*k_i*s*sin(theta_i)*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)) + 6*k_i*s^2*cos(theta_i)*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i)) + 6*k_i*s^2*sin(theta_i)*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)))^(1/2)) -((6*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)) - 6*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)))*s^2 + (6*k_i*sin(theta_i)*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i)) - 6*k_i*cos(theta_i)*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)))*s - 2*k_i*sin(theta_i)*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) + 2*k_i*cos(theta_i)*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)))/(k_i^2*cos(theta_i)^2 - s*(4*k_i*sin(theta_i)*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)) + 4*k_i*cos(theta_i)*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))) + k_i^2*sin(theta_i)^2 + s^4*(9*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))^2 + 9*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))^2) - s^3*(12*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) + 12*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i))) + s^2*(4*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))^2 + 4*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i))^2 + 6*k_i*sin(theta_i)*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)) + 6*k_i*cos(theta_i)*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i)))) c((2*s/0.02+2)) = alphamin * ((9*s^4*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))^2 + 4*s^2*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i))^2 + k_i^2*cos(theta_i)^2 + k_i^2*sin(theta_i)^2 + 9*s^4*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))^2 + 4*s^2*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))^2 - 12*s^3*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)) - 12*s^3*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) - 4*k_i*s*cos(theta_i)*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) - 4*k_i*s*sin(theta_i)*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)) + 6*k_i*s^2*cos(theta_i)*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i)) + 6*k_i*s^2*sin(theta_i)*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)))^(1/2)) - (-((6*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)) - 6*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)))*s^2 + (6*k_i*sin(theta_i)*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i)) - 6*k_i*cos(theta_i)*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)))*s - 2*k_i*sin(theta_i)*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) + 2*k_i*cos(theta_i)*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)))/(k_i^2*cos(theta_i)^2 - s*(4*k_i*sin(theta_i)*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i)) + 4*k_i*cos(theta_i)*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))) + k_i^2*sin(theta_i)^2 + s^4*(9*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))^2 + 9*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))^2) - s^3*(12*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i)) + 12*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i))*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i))) + s^2*(4*(3*x_i - 3*x_f + k_f*cos(theta_f) + 2*k_i*cos(theta_i))^2 + 4*(3*y_i - 3*y_f + k_f*sin(theta_f) + 2*k_i*sin(theta_i))^2 + 6*k_i*sin(theta_i)*(2*y_i - 2*y_f + k_f*sin(theta_f) + k_i*sin(theta_i)) + 6*k_i*cos(theta_i)*(2*x_i - 2*x_f + k_f*cos(theta_f) + k_i*cos(theta_i))))) endceq=[];end
The error i get:
Array indices must be positive integers or logical values.
What can i do?
Best Answer