Solving state space equation by ode45
조회 수: 66 (최근 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
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.
채택된 답변
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)]
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!