Find the optimal state and optimal control based on minimizing the performance index
11 views (last 30 days)
Show older comments
Kunal Jain on 22 Feb 2022
Answered: Abolfazl Chaman Motlagh on 22 Feb 2022
Find the optimal state and optimal control based on minimizing the performance index 𝐽=∫ (𝑥(𝑡) − 1/2 (𝑢(𝑡)^2) ) 𝑑𝑡 , 0 ≤ 𝑡 ≤ 1 subject to 𝑢(𝑡) = 𝑥̇(𝑡) + 𝑥(𝑡) with the condition 𝑥(0) = 0, 𝑥(1) = 1 2 (1 − 1 /e )^2 where 𝐽𝑒𝑥𝑎𝑐𝑡 = 0.08404562020 In this example the initial approximation is 𝑥1 (𝑡) = 1/2 (1 − 1 /e ) ^2
I saw there are warnings in global variables and was thinking of alternative of global variables. Please explain this giving an example.
Error using fmincon (line 641)
Supplied objective function must return a scalar value.
Error in solve_system_of_equations (line 40)
x = fmincon(fun,x0,A,bb,Aeq,beq,lb,ub);
function F = cost_function(x)
F= x - 1/2*(u*u');
function F = system_of_equations(x)
x1=(C1*P_alpha_1*m.H) + init(1);
F = horzcat( D_alpha1_x1 + x1 - u , ...
(C1*P_alpha_1*HC) + init(1) - (1/2*((1-exp(-1))^2))) ;
k=8; %no. of Haar wavelets
b=2; %Total number of days to plot
A = ;
bb = ;
Aeq = ;
beq = ;
lb = ;
ub = ;
fun = @cost_function;
x = fmincon(fun,x0,A,bb,Aeq,beq,lb,ub,nonlcon)
Abolfazl Chaman Motlagh on 22 Feb 2022
your cost_function doesn't return a scalar. it should return one number for every input.
it seems that x is a 1xn vector. and u is a vector with same size as x. (for every t i guess!) but in last line of cost_function you write F = x - 1/2*(u*u') . the second term is a scalar beacuse it is inner product of u with itself make this term become . but x is still a vector so the result (F) become 1xn vector. F should be integration if x and u are vector with same size and space. you should sum it over time. (with dt !) : becoming :
F = sum(x + 0.5*u.^2)
also this might not be a good choice becuse it doen't contain any information about t and the integration is over t. if grid of t is uniform and the intervals are equal summation and numerical integration is different in just a constant coefficient which doesn't change the problem. but integration over t might be better soltion in general:
F = trapz(x+0.5*(u.^2)); %numerical integration with Trapezoidal method
if you have the value of t : (t as vector)
F = trapz(t,x+0.5*(u.^2));
Find more on Choose a Solver 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!