N min Σσκ-1Δ æk,uk s.t. k=1 xk+1 = Akxk + Bkuk + ck Akxk+Bkuk Ck - -Zibk Tmine kok≤ Tmax C¯¯zbk [1 − (Zk - Zbk)], ||ak||2 ≤ ok - ||Srk bj₂+drk + hj ≤0, xo = [r], vŢ,mo]', rN = 0, T T 2lbk≤zk VN = 0 where xk = [57, vk, zk]" and uk = [a‚σk]¯. Zlbk = Zlb(tk). 'k' (objective function) (14a) (dynamical constraints) (14b) (control constraints) (14c) (state path constraints) (14d) (boundary constraints) (14e)

Elements Of Electromagnetics
7th Edition
ISBN:9780190698614
Author:Sadiku, Matthew N. O.
Publisher:Sadiku, Matthew N. O.
ChapterMA: Math Assessment
Section: Chapter Questions
Problem 1.1MA
icon
Related questions
Question

I need help with a MATLAB code. I am trying to solve this question. Based on the Mars powered landing scenario
solve Eq. (14) via convex programming. Report the consumed fuel, and discuss the results with relevant plots. I am using the following MATLAB code and getting an error. I tried to fix the error and I get another one saying something about log and exp not being convex. Can you help fix my code and make sure it works.

 

The error is CVX Warning:
  Models involving "log" or other functions in the log, exp, and entropy
  family are solved using an experimental successive approximation method.
  This method is slower and less reliable than the method CVX employs for
  other models. Please see the section of the user's guide entitled
      The successive approximation method
  for more details about the approach, and for instructions on how to
  suppress this warning message in the future.
Error using  .*  (line 173)
Disciplined convex programming error:
   Cannot perform the operation: {log-affine} .* {real affine}

Error in  *  (line 36)
   z = feval( oper, x, y );
       ^^^^^^^^^^^^^^^^^^^
Error in untitled7 (line 60)
           T_min * exp(-x(7, k)) <= u(1, k) <= T_max * exp(-x(7, k)) * (1 - (x(7, k) - z_lb));
                                                                     ^

>> 

 

 

 

clc;

clear all;

 

% Define the given parameters

g = -3.7114e-3; % Gravitational acceleration in km/s^2

alpha = 0.5086; % Fuel consumption rate in s/km

T_min = 4.97; % Minimum thrust in kg·km/s^2

T_max = 13.26; % Maximum thrust in kg·km/s^2

delta_t = 1.0; % Time step in seconds

N = 78; % Number of time steps

r0 = [1.5; 0; 2.0]; % Initial position in km

v0 = [-0.075; 0.03; 0.1]; % Initial velocity in km/s

m0 = 2000; % Initial mass in kg

gamma_min = 3; % Minimum glide slope angle in degrees

 

% Initial conditions

x0 = [r0; v0; log(m0)]; % Initial state: [position, velocity, log(mass)]

z_lb = 0;

 

% Define matrices for the optimization

cvx_begin

variables x(7, N) u(4, N) log_mass(1, N) exp_mass(1, N) % Auxiliary variables for log and exp terms

 

% Objective function: minimize the total fuel consumption

minimize( sum(sum(u)) ) % This would correspond to the sum of fuel used

 

 

 

for k = 1:N-1

% Dynamic constraints (from Eq. (14b)) - Define A_k, B_k, and c_k

% Compute A_k, B_k, c_k for each time step

[A_k, B_k, c_k] = computeMatrices(x(:, k), g);

 

% State transition equation (Eq. (14b))

x(:, k+1) == A_k * x(:, k) + B_k * u(:, k) + c_k; % You will need to compute A_k, B_k, c_k

 

% Control constraints (from Eq. (14c))

T_min * exp(-x(7, k)) <= u(1, k) <= T_max * exp(-x(7, k)) * (1 - (x(7, k) - z_lb));

norm(u(:, k), 2) <= u(1, k); % Thrust bound

 

% Path constraints (from Eq. (14d))

norm(S_k * x(1:3, k) - b_k) + d_k' * x(1:3, k) + h_j <= 0; % State path constraints

x(7, k) >= z_lb(k); % Mass bound (from boundary conditions)

end

 

% Boundary conditions (from Eq. (14e))

x(:, 1) == x0; % Initial state constraint

x(1:3, N) == 0; % Final position is zero

x(4:6, N) == 0; % Final velocity is zero

cvx_end

 

% Fuel consumption (objective value)

fuel_consumed = cvx_optval;

 

% Plot results

% Example for plotting control inputs:

figure;

plot(1:N, u(1, :), 'LineWidth', 2);

title('Thrust Magnitude Over Time');

xlabel('Time step');

ylabel('Thrust Magnitude (kg·km/s^2)');

 

% Example for plotting fuel consumption

disp('Total Fuel Consumed:');

disp(fuel_consumed);

 

%% Function to compute A_k, B_k, and c_k

function [A_k, B_k, c_k] = computeMatrices(x_k, g)

% A_k is a 7x7 matrix

A_k = cvx(zeros(7, 7)); % Initialize as a zero matrix

 

% Fill A_k dynamics

A_k(1:3, 4:6) = eye(3); % position dynamics

A_k(4:6, 7) = -g * ones(3,1); % gravity term on velocity

 

% B_k is 7x4 matrix

B_k = cvx(zeros(7, 4));

B_k(4:6, 1:3) = eye(3); % control inputs affect velocity

 

% c_k vector (nonlinear effects)

c_k = cvx(zeros(7, 1));

c_k(4:6) = -g * x_k(7); % nonlinear gravity term depending on mass

end

 

N
min Σσκ-1Δ
æk,uk
s.t.
k=1
xk+1 = Akxk + Bkuk + ck
Akxk+Bkuk Ck
-
-Zibk
Tmine kok≤ Tmax C¯¯zbk [1 − (Zk - Zbk)], ||ak||2 ≤ ok
-
||Srk bj₂+drk + hj ≤0,
xo = [r], vŢ,mo]', rN = 0,
T T
2lbk≤zk
VN = 0
where xk = [57, vk, zk]" and uk = [a‚σk]¯. Zlbk = Zlb(tk).
'k'
(objective function) (14a)
(dynamical constraints) (14b)
(control constraints) (14c)
(state path constraints) (14d)
(boundary constraints) (14e)
Transcribed Image Text:N min Σσκ-1Δ æk,uk s.t. k=1 xk+1 = Akxk + Bkuk + ck Akxk+Bkuk Ck - -Zibk Tmine kok≤ Tmax C¯¯zbk [1 − (Zk - Zbk)], ||ak||2 ≤ ok - ||Srk bj₂+drk + hj ≤0, xo = [r], vŢ,mo]', rN = 0, T T 2lbk≤zk VN = 0 where xk = [57, vk, zk]" and uk = [a‚σk]¯. Zlbk = Zlb(tk). 'k' (objective function) (14a) (dynamical constraints) (14b) (control constraints) (14c) (state path constraints) (14d) (boundary constraints) (14e)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Elements Of Electromagnetics
Elements Of Electromagnetics
Mechanical Engineering
ISBN:
9780190698614
Author:
Sadiku, Matthew N. O.
Publisher:
Oxford University Press
Mechanics of Materials (10th Edition)
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:
9780134319650
Author:
Russell C. Hibbeler
Publisher:
PEARSON
Thermodynamics: An Engineering Approach
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:
9781259822674
Author:
Yunus A. Cengel Dr., Michael A. Boles
Publisher:
McGraw-Hill Education
Control Systems Engineering
Control Systems Engineering
Mechanical Engineering
ISBN:
9781118170519
Author:
Norman S. Nise
Publisher:
WILEY
Mechanics of Materials (MindTap Course List)
Mechanics of Materials (MindTap Course List)
Mechanical Engineering
ISBN:
9781337093347
Author:
Barry J. Goodno, James M. Gere
Publisher:
Cengage Learning
Engineering Mechanics: Statics
Engineering Mechanics: Statics
Mechanical Engineering
ISBN:
9781118807330
Author:
James L. Meriam, L. G. Kraige, J. N. Bolton
Publisher:
WILEY