error in matlab code
I have been trying to solve an optimal problem in which a body of mass have to [be] transfered to y(tf) = 0 from its initial position y(o) = 0 such that its final velocity is zero satisfying the performance index.
, where t = [to, tf].
But I am not getting the optimal trajectories using this code. Could anyone help me to find where the mistake [is]?
clear all
c0 = [0.1; 0.1; 0.1; 0.1; 5]; % Make a starting guess at the solution
[c, fval] = fsolve (@myfun1, c0) % Call optimizer
c1 = c(1); c2 = c(2); c3 = c(3); c4 = c(4); c5 = c(5);
t=0:0.01:c5;
x1op = -(c1*(t.^3))/6-(c2*(t.^2))/2+(c3.*t)+c4
x2op =-(c1*(t.^2))/2+-(c2.*t)+c3
uop = -(c1.*t)-c2
lam1= c1;
H = 1.5 * uop.^2 + x2op.* lam1;
figure (1)
plot(t, uop)
figure(2)
plot(t,x1op,t,x2op)
figure(3)
plot(t,H)
function F = myfun1(c)
x10 = 1;
x20 = 0;
x1f = 0;
x2f = 0;
u=-(c(1)*c(5))-c(2);
ud = c(1);
% the conditions x1(t = 0), x1(t = tf), x2(t = 0), x2(t = tf)
f1 = c(4)-x10;
f2 =-(c(1)*(c(5)^3))/6 -(c(2)*(c(5)^2))/2 +(c(3)*c(5)) + 1 -x1f;
f3 = c(3)-x20;
f4 = -(c(1)*(c(5)^2))/2 -(c(2)*c(5))-x2f;
f5 = 1.5 *u.^2 -f4.*ud ;% the condition H(tf) = 0
F = [f1;f2;f3;f4;f5]; % the five unknown system F(C) = 0
endI have been trying to solve an optimal problem in which a body of mass have to [be] transfered to y(tf) = 0 from its initial position y(o) = 0 such that its final velocity is zero satisfying the performance index.
, where t = [to, tf].
But I am not getting the optimal trajectories using this code. Could anyone help me to find where the mistake [is]?
clear all
c0 = [0.1; 0.1; 0.1; 0.1; 5]; % Make a starting guess at the solution
[c, fval] = fsolve (@myfun1, c0) % Call optimizer
c1 = c(1); c2 = c(2); c3 = c(3); c4 = c(4); c5 = c(5);
t=0:0.01:c5;
x1op = -(c1*(t.^3))/6-(c2*(t.^2))/2+(c3.*t)+c4
x2op =-(c1*(t.^2))/2+-(c2.*t)+c3
uop = -(c1.*t)-c2
lam1= c1;
H = 1.5 * uop.^2 + x2op.* lam1;
figure (1)
plot(t, uop)
figure(2)
plot(t,x1op,t,x2op)
figure(3)
plot(t,H)
function F = myfun1(c)
x10 = 1;
x20 = 0;
x1f = 0;
x2f = 0;
u=-(c(1)*c(5))-c(2);
ud = c(1);
% the conditions x1(t = 0), x1(t = tf), x2(t = 0), x2(t = tf)
f1 = c(4)-x10;
f2 =-(c(1)*(c(5)^3))/6 -(c(2)*(c(5)^2))/2 +(c(3)*c(5)) + 1 -x1f;
f3 = c(3)-x20;
f4 = -(c(1)*(c(5)^2))/2 -(c(2)*c(5))-x2f;
f5 = 1.5 *u.^2 -f4.*ud ;% the condition H(tf) = 0
F = [f1;f2;f3;f4;f5]; % the five unknown system F(C) = 0
end I have been trying to solve an optimal problem in which a body of mass have to [be] transfered to y(tf) = 0 from its initial position y(o) = 0 such that its final velocity is zero satisfying the performance index.
, where t = [to, tf].
But I am not getting the optimal trajectories using this code. Could anyone help me to find where the mistake [is]?
clear all
c0 = [0.1; 0.1; 0.1; 0.1; 5]; % Make a starting guess at the solution
[c, fval] = fsolve (@myfun1, c0) % Call optimizer
c1 = c(1); c2 = c(2); c3 = c(3); c4 = c(4); c5 = c(5);
t=0:0.01:c5;
x1op = -(c1*(t.^3))/6-(c2*(t.^2))/2+(c3.*t)+c4
x2op =-(c1*(t.^2))/2+-(c2.*t)+c3
uop = -(c1.*t)-c2
lam1= c1;
H = 1.5 * uop.^2 + x2op.* lam1;
figure (1)
plot(t, uop)
figure(2)
plot(t,x1op,t,x2op)
figure(3)
plot(t,H)
function F = myfun1(c)
x10 = 1;
x20 = 0;
x1f = 0;
x2f = 0;
u=-(c(1)*c(5))-c(2);
ud = c(1);
% the conditions x1(t = 0), x1(t = tf), x2(t = 0), x2(t = tf)
f1 = c(4)-x10;
f2 =-(c(1)*(c(5)^3))/6 -(c(2)*(c(5)^2))/2 +(c(3)*c(5)) + 1 -x1f;
f3 = c(3)-x20;
f4 = -(c(1)*(c(5)^2))/2 -(c(2)*c(5))-x2f;
f5 = 1.5 *u.^2 -f4.*ud ;% the condition H(tf) = 0
F = [f1;f2;f3;f4;f5]; % the five unknown system F(C) = 0
end optimal control MATLAB Answers — New Questions