i have some error in my MATLAB code .

% EQUATION OF FLIGHT DYNAMICS IN STATE SPACE FORM
% state space matrix
A = [-0.00871, -0.019, -135, -32.12;
-0.0117, -0.311, 1931, -2.246;
0.0004761, -0.00673, -0.182, 0;
0, 0, 1, 0];
B = [6.24; -89.2; -9.80; 0];
C = [-0.127, 0.0698, -0.998, 0.01659;
-2.36, -1.02, 0.0103, 0;
11.1, -0.00735, -0.196, 0;
0, 1, 0, 0];
D = [-0.00498, 0.0426;
28.7, 5.38;
0.993, -6.90;
0, 0];
% control inputs (ELEVATOR,AILERON,RUDDER)
delta_e = @(t) [0; 0; 0; 0];
% state derivative function
state_derivative = @(t, x) A * x + B * delta_e(t);
% initial condition
initial_state = zeros(4,1);
%timespan--------------------------------------------------------------
tspan = [0, 10];
%solving equation using ode45
[t, x] = ode45(state_derivative, tspan, initial_state);
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.

Error in solution>@(t,x)A*x+B*delta_e(t) (line 23)
state_derivative = @(t, x) A * x + B * delta_e(t);

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
%%%ploting results------------------------------------------------------
figure;
subplot(2, 2, 1);
plot(t, x(:, 1));
xlabel('Time (s)');
ylabel('u');
title('velocity u');
subplot(2, 2, 2);
plot(t, x(:, 2));
xlabel('Time (s)');
ylabel('\omega');
title('angular velocity \omega');
subplot(2, 2, 3);
plot(t, x(:, 3));
xlabel('Time (s)');
ylabel('q');
title('pitch rate q');
subplot(2, 2, 4);
plot(t, x(:, 4));
xlabel('Time (s)');
ylabel('\theta');
title('pitch angle \theta');

Answers (1)

B*delta_e(t)
is undefined since B and delta_e(t) are both 4x1.
Maybe you mean
B.*delta_e(t)
instead.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 2 Oct 2023

Answered:

on 2 Oct 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!