Input arguments to function include colon operator. To input the colon character, use ':' instead.
Show older comments
I am trying to run fmincon and i get this error:
Input arguments to function include colon operator. To input the colon character, use ':' instead.
I cannot understand why I get this error.
My code is below. How to correct it?
Anyone any ideas? Thank you.
a=[1.010974995;-0.00337119;0;0;0];
fmincon('obj',[a;rand(10,1);1.8603],[],[],[],[],[],[],'cons')
Input arguments to function include colon operator. To input the colon character, use ':' instead.
fmincon (line 645)
initVals.nceq = ceqtmp(:);
function [j,h]=cons(X)
a1 = X(1); a2 = X(2); a3 = X(3); a4 = X(4); a5 = X(5);
b1 = X(6); b2 = X(7); b3 = X(8); b4 = X(9); b5 = X(10);
c1 = X(11);c2 = X(12);c3 = X(13);c4 = X(14);c5 = X(15);
tf= X(16);
syms t a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4 c5
r = a1 + a2*t^1 + a3*t^2 + a4*t^3 + a5*t^4;
x = b1 + b2*t^1 + b3*t^2 + b4*t^3 + b5*t^4;
y = c1 + c2*t^1 + c3*t^2 + c4*t^3 + c5*t^4;
dr = diff(r,t);
dx = diff(x,t);
dy = diff(y,t);
v = sqrt(dr^2+dx^2+dy^2);
gamma = asin(dr/(sqrt(dr^2+dx^2+dy^2)));
psi = atan(dx/dy);
dv = diff(v,t);
dgamma= diff(gamma,t);
%dpsi = diff(psi,t);
m = 907;
g0 = 9.81;
g = g0.*((1./r)^2);
R0 = 6378135;
Sref = 0.4839;
Ma = v * sqrt(g0*R0) / 340.3;
rho0 = 1.226;
rho = rho0.*exp(-(r-1).*R0./7254.24);
Da = -dv-sin(gamma)/(r^r);
CD = (2*m*g*Da) / (Sref*rho*v^2);
syms alpha1
CD_ = 0.02467+0.0007143.*alpha1.*alpha1+0.3252.*exp(-0.279.*Ma);
alpha_ = solve((CD-CD_),alpha1);
CL = -0.2342+0.05136.*alpha_+0.2943.*exp(-0.1007.*Ma);
La = (Sref*CL*rho*v^2) / (2*m*g);
syms cossigma sinsigma
cossigma = (dgamma*v - (v^2-1/r)*(cos(gamma)/r))/La;
sinsigma1 = sqrt(1-cossigma(1)^2);
sinsigma2 = sqrt(1-cossigma(2)^2);
phi = int(v*cos(gamma)*cos(psi)/r,t);
theta = int(v*cos(gamma)*sin(psi)/(r*cos(phi)),t);
r0 = subs(r,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[0,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
phi0 = subs(phi,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[0,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
theta0= subs(theta,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[0,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
v0 = subs(v,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[0,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
gamma0= subs(gamma,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[0,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
psi0 = subs(psi,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[0,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
syms tf
rf = subs(r,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[tf,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
vf = subs(v,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[tf,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
dpsi1_ = ((La*sinsigma1)/cos(gamma)+v*v/r*cos(gamma)*sin(psi)*tan(phi))/v;
psi1_ = int(dpsi1_,t,tf,0);
dpsi2_ = ((La*sinsigma2)/cos(gamma)+v*v/r*cos(gamma)*sin(psi)*tan(phi))/v;
psi2_ = int(dpsi2_,t,tf,0);
h1 = [r0-(6378.135+70)/6378.135
phi0-0
theta0-0
v0-(6000/sqrt(g0*R0))
gamma0-0
psi0-(pi/2)];
h2 = [rf-(6378.135+30)/6378.135
vf-(1500/sqrt(g0*R0))];
h_ = [h1;h2;psi1_-psi];
h = matlabFunction(h_);
j = [];
end
function f=obj(X)
a1 = X(1); a2 = X(2); a3 = X(3); a4 = X(4); a5 = X(5);
b1 = X(6); b2 = X(7); b3 = X(8); b4 = X(9); b5 = X(10);
c1 = X(11);c2 = X(12);c3 = X(13);c4 = X(14);c5 = X(15);
tf= X(16);
syms a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4 c5 t tf
r = a1 + a2*t^1 + a3*t^2 + a4*t^3 + a5*t^4;
x = b1 + b2*t^1 + b3*t^2 + b4*t^3 + b5*t^4;
y = c1 + c2*t^1 + c3*t^2 + c4*t^3 + c5*t^4;
dr = diff(r,t);
dx = diff(x,t);
dy = diff(y,t);
v = sqrt(dr^2+dx^2+dy^2);
gamma = asin(dr/(sqrt(dr^2+dx^2+dy^2)));
psi = atan(dx/dy);
phi = int(v*cos(gamma)*cos(psi)/r,t);
theta = int(v*cos(gamma)*sin(psi)/(r*cos(phi)),t);
thetaf= subs(theta,[t,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5],[tf,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,c1,c2,c3,c4,c5]);
f_ =(-thetaf);
end
1 Comment
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!