Solving state space equation by ode45

22 ビュー (過去 30 日間)
Basetsana Sebolao
Basetsana Sebolao 2021 年 5 月 12 日
コメント済み: Star Strider 2021 年 5 月 17 日
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
.
  2 件のコメント
Basetsana Sebolao
Basetsana Sebolao 2021 年 5 月 17 日
Thank you!
Star Strider
Star Strider 2021 年 5 月 17 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by