clear, clc, clear yalmip
opts = sdpsettings();
opts.solver = 'sdtp';
opts.cdcs.maxIter = 1e4;
opts.cdcs.solver = 'sos';
Re = 400; % CHANGE Re TO DESIRED VALUE
% Generating the full system
[N_ijk, L_ij, B_i] = Shear_Model_9_Mode(Re);
Size_N_ijk = size(N_ijk);
N = Size_N_ijk(1);
% Use UODESys tool to undergo variable transformation
Variable_Transformation
% Use UODESys tool to find bound for Theta and value for KAPPA
Bounds_Calculation
% Define column vector of variables [a_1; ... ;a_n]
a = sdpvar(n,1);
% Represent the 3D array N_hat_xyz as a cell array.
N_hat_xyz_final_array = cell(1,n);
for x = 1:n
N_hat_xyz_final_array{1,x} = zeros(n,n);
for y = 1:n
N_hat_xyz_final_array{1,x}(y,:) = N_hat_xyz_final(x,y,:);
end
end
% Represent N_hat_xyz_final_array as a 2D matrix.
nnl_mat = [N_hat_xyz_final_array{1}(:)'; N_hat_xyz_final_array{2}(:)'; N_hat_xyz_final_array{3}(:)'; N_hat_xyz_final_array{4}(:)'];
% Define f=da/dt for new truncated system using Transformed N,L and B
% matrices
a2 = a*a';
lin = B_hat_x_final + L_hat_xy_final*a;
nnl = nnl_mat*a2(:);
f = lin + nnl;
% Assign values to the sdpvar decision variables.
assign(c_1,value(c_1))
assign(c_2,value(c_2))
assign(c_3,value(c_3))
sdpvar r;
vector_of_variables = [a;r];
%Create storage function V that is a function of u and q^2
[V_6,c_6,mono_6] = polynomial([vector_of_variables],6,1);
%Jacobian of V
F = jacobian(V_6,[vector_of_variables]);
%Assign q^2 as variable, equal to norm(v)/2
sdpvar q;
qsquared = q^2;
%Define phi as sum of squares of u1,...un + q^2
phi = norm_u_sq + qsquared;
%replace r with qsquared in jacobian F
replace(F,r,qsquared);
%Assign variable z0 and z
sdpvar z0
z = sdpvar(n,1);
%Assing expression for P
norm_a_sq = a'*a;
P = c_1*qsquared + c_2*norm_a_sq*2*qsquared + c_3*qsquared^2*4;
%Solve for upperbound
sdpvar upperbound
Constupper=sos(-(((P*z0^2)+z'*z)*(F(1:n)*f + (F(n+1)*KAPPA*qsquared) + phi - upperbound)') - (2*P*z0*(F(1:n)-F(n+1)*a')*z));
solvesos(Constupper, upperbound,[opts],[a;qsquared;upperbound;c_6]);