Solving state space equation by ode45

21 views (last 30 days)
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 Comments
Star Strider
Star Strider on 12 May 2021
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 on 12 May 2021
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

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 12 May 2021
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
.

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!