immi
Newbie level 1
proposed solution using matlab
syms u lam1 lam2 lam3 x1 x2 x3 real % define symbolic variables
x = [x1 x2 x3]';
lambda = [lam1 lam2 lam3]';
f = [(1-x(2)^2)*x(1)-x(2)+u;x(1);x(1)^2+x(2)^2+u^2];% State dynamics
phi = 0; L = x(3); % Terms in the objective function
H = L + lambda'*f;
lam_dot = -jacobian(H,x)';
lam_final = jacobian(phi,x)'
uopt = solve(diff(H,u),u);
x_dot = subs(f,u,uopt); %subs = subsitution of u with uopt in f[state equation]
zdot=@(t,z)[ ...
- z(2) - z(1)*(z(2)^2 - 1) - z(4)/(2*z(6));...
z(1); ...
z(1)^2 + z(2)^2 + z(4)^2/(4*z(6)^2); ...
z(4)*(z(2)^2 - 1) - z(5) - 2*z(6)*z(1); ...
z(4)*(2*z(1)*z(2) + 1) - 2*z(6)*z(2); ...
-1];
x0 = [0;1;0]; lam_final = [0;0;0];
BCres = @(a,b) [a(1:2:3)- x0;b(4:5:6)- (lam_final)]
solinit = bvpinit(linspace(0,5),[-5 1 0 0 1 5])
sol = bvp4c(zdot,BCres,solinit);
When the bvp4c is used i get error.
Any help regarding this problem. Thanks in advance