i have some error in my MATLAB code .

조회 수: 1 (최근 30일)
shailendra
shailendra . 2023년 10월 2일
답변: Torsten . 2023년 10월 2일
% 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');

답변 (1개)

Torsten
Torsten 2023년 10월 2일
B*delta_e(t)
is undefined since B and delta_e(t) are both 4x1.
Maybe you mean
B.*delta_e(t)
instead.

카테고리

Help CenterFile Exchange에서 Model Order Reduction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by