Solve a system of differential equations which has blkdiag

2 vues (au cours des 30 derniers jours)
Hoang Vu Huy
Hoang Vu Huy le 21 Fév 2023
Déplacé(e) : Torsten le 23 Fév 2023
I want to solve following equation:
with
Matrices A and C are defined.
I want use ode45 to solve, but I don't know to define matrix B.
function dpdt = control_law(t,xe)
global A C
x = xe(1:2*n,1);
y = xe(2*n+1:end,1);
dxdt = Ax +By (????????)
dydt = C*x;
dpdt = [dxdt;dydt];
end
I tried some of the analysis but to no avail

Réponses (3)

Torsten
Torsten le 23 Fév 2023
Déplacé(e) : Torsten le 23 Fév 2023
x = [1;2;3;4;5;6];
x = reshape(x,2,[]);
B = arrayfun(@(i)squeeze(kron(x(:,i).',eye(2))),1:size(x,2),'UniformOutput',0);
C = blkdiag(B{:})
C = 6×12
1 0 2 0 0 0 0 0 0 0 0 0 0 1 0 2 0 0 0 0 0 0 0 0 0 0 0 0 3 0 4 0 0 0 0 0 0 0 0 0 0 3 0 4 0 0 0 0 0 0 0 0 0 0 0 0 5 0 6 0 0 0 0 0 0 0 0 0 0 5 0 6

Luca Ferro
Luca Ferro le 21 Fév 2023
Modifié(e) : Luca Ferro le 21 Fév 2023
given i as identity with coeherent dimensions to x:
blkdiag(x'.*i)
edit: to create i use the eye(n) function, where n is the dimensions
  1 commentaire
Hoang Vu Huy
Hoang Vu Huy le 22 Fév 2023
Sorry, I don't understand your idea. Please re-explain

Connectez-vous pour commenter.


Torsten
Torsten le 21 Fév 2023
Déplacé(e) : Torsten le 21 Fév 2023
You can't supply it as a global, but only pass it as a function handle:
B = @(x) blkdiag(kron(x.',eye(2)))
Or you define it as
B = blkdiag(kron(x.',eye(2)))
in the function.
  1 commentaire
Hoang Vu Huy
Hoang Vu Huy le 22 Fév 2023
I try but I think it's not true
For example, , that mean
I want to creat matrix , so B equals
But, I run your code B = blkdiag(kron(x.',eye(2))), B equals:

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by