Solving state space equation by ode45
27 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Basetsana Sebolao
le 12 Mai 2021
Commenté : Star Strider
le 17 Mai 2021
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 commentaires
Star Strider
le 12 Mai 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.
Réponse acceptée
Star Strider
le 12 Mai 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)]
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

