Effacer les filtres
Effacer les filtres

Continuing Matrix involving a function to make very large

1 vue (au cours des 30 derniers jours)
Seb apple
Seb apple le 17 Juin 2020
Hi all, i have a typed square matrix and need to expand it to be very large how ever this will take far too long to do manually. my matrix code is below please help if you know any function to expend it while keeping the same pattern.
thanks in advance
syms e P n
c=1;
G(n)=e/(2*(P+0.5*(1i*n*c)-(0.25*(n)^2)));
j=[1 0 G(7) 0 0 0 0 0 0 0 0 0 0 0 0;0 1 0 G(6) 0 0 0 0 0 0 0 0 0 0 0; G(5) 0 1 0 G(5) 0 0 0 0 0 0 0 0 0 0; 0 G(4) 0 1 0 G(4) 0 0 0 0 0 0 0 0 0; 0 0 G(3) 0 1 0 G(3) 0 0 0 0 0 0 0 0; 0 0 0 G(2) 0 1 0 G(2) 0 0 0 0 0 0 0; 0 0 0 0 G(1) 0 1 0 G(1) 0 0 0 0 0 0 ; 0 0 0 0 0 G(0) 0 1 0 G(0) 0 0 0 0 0; 0 0 0 0 0 0 G(-1) 0 1 0 G(-1) 0 0 0 0; 0 0 0 0 0 0 0 G(-2) 0 1 0 G(-2) 0 0 0; 0 0 0 0 0 0 0 0 G(-3) 0 1 0 G(-3) 0 0; 0 0 0 0 0 0 0 0 0 G(-4) 0 1 0 G(-4) 0; 0 0 0 0 0 0 0 0 0 0 G(-5) 0 1 0 G(-5); 0 0 0 0 0 0 0 0 0 0 0 G(-6) 0 1 0; 0 0 0 0 0 0 0 0 0 0 0 0 G(-7) 0 1 ];
  2 commentaires
KSSV
KSSV le 17 Juin 2020
'P' not defined.
KSSV
KSSV le 17 Juin 2020
Read about diag.

Connectez-vous pour commenter.

Réponses (1)

Ameer Hamza
Ameer Hamza le 17 Juin 2020
Try this
syms e o n
c=1;
P = 1;
G(n)=e./(2.*(P+0.5*(1i*n.*c)-(0.25*(n)^2)));
N = 15;
l_start = 5;
u_start = 7;
l_end = l_start-N+3;
u_end = u_start-N+3;
j = diag(ones(1,N)) + diag(G(l_start:-1:l_end), -2) + diag(G(u_start:-1:u_end), 2);

Catégories

En savoir plus sur Matrices and Arrays 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!

Translated by