Solve a system of differential equations which has blkdiag
이전 댓글 표시
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
답변 (3개)
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{:})
Luca Ferro
2023년 2월 21일
편집: Luca Ferro
2023년 2월 21일
0 개 추천
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
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.
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
