Solving state space equation by ode45

73 次查看(过去 30 天)
Helo everyone
I am trying to solve a state space matrix using ode45. My A matrix is a 4 x 4, my B matrix is a 4 x 4 and my input matrix, v is a 4 x 1. I am expecting a matrix of 4 x 1 however when I run my code Matlab indicates that my t and y arrays have 185853 rows in my workspace, which is befuddling because I do not understand why my matrix has a lot of rows.I have attached a picture of my code. Pease kindly assist, thank you in advance.
  2 个评论
Star Strider
Star Strider 2021-5-12
Please copy and paste all the relevant code to either an edit to your original post here or to a Comment. Screenshots can be appropriate for plots and other images, however not for code.
Basetsana Sebolao
Basetsana Sebolao 2021-5-12
Noted, thank you. I have copied and pasted my code below:
function di = sys(t, i)
Rs=1.115;Rr=1.0830; Wr=1150; Lm= 76.79; Ls=79.04; Lr=79.04; Ws=376;
R=[Rs 0 0 0; 0 Rs 0 0; 0 0 Rr 0; 0 0 0 Rr];
G=[ 0 0 0 0; 0 0 0 0; 0 -Lm 0 -Lr; Lm 0 Lr 0];
L=[Ls 0 Lm 0; 0 Ls 0 Lm; Lm 0 Lr 0; 0 0 0 Rr];
k=1/(Ls*Lr-Lm*Lm);
%A is a 4x4 matrix
A=-L*(R+(Wr*G));
%B is a 4x4 matrix
B= k*[Lr 0 -Lm 0; 0 Lr 0 -Lm; -Lm 0 Rs 0; 0 -Lm 0 Ls];
%V is a 4x1 matrix
v = [t; 0; 0; 0];
%state equation
di = A*i + B*v;
end

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2021-5-12
The MATLAB ODE solvers are adaptive, and so will solve with as narrow a difference in the time steps as necessary to produce a stable solution. In your differential equation solution, there are very rapid oscillations with increasing amplitudes beginning at about time units.
tspan = [0 0.005];
iniCon = [0 0 0 0];
[t,y] = ode45(@sys, tspan, iniCon);
getSizes = [size(t); size(y)]
getSizes = 2×2
185853 1 185853 4
figure
plot(t, y)
grid
figure
cols = size(y,2);
for k = 1:cols
subplot(cols,1,k)
plot(t, y(:,k))
grid
xlim([0 1.5E-4])
title(sprintf('y_{%d}',k))
end
xlabel('t')
function di = sys(t, i)
Rs=1.115;Rr=1.0830; Wr=1150; Lm= 76.79; Ls=79.04; Lr=79.04; Ws=376;
R=[Rs 0 0 0; 0 Rs 0 0; 0 0 Rr 0; 0 0 0 Rr];
G=[ 0 0 0 0; 0 0 0 0; 0 -Lm 0 -Lr; Lm 0 Lr 0];
L=[Ls 0 Lm 0; 0 Ls 0 Lm; Lm 0 Lr 0; 0 0 0 Rr];
k=1/(Ls*Lr-Lm*Lm);
%A is a 4x4 matrix
A=-L*(R+(Wr*G));
%B is a 4x4 matrix
B= k*[Lr 0 -Lm 0; 0 Lr 0 -Lm; -Lm 0 Rs 0; 0 -Lm 0 Ls];
%V is a 4x1 matrix
v = [t; 0; 0; 0];
%state equation
di = A*i + B*v;
end
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by