Continuing Matrix involving a function to make very large
1 次查看(过去 30 天)
显示 更早的评论
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 ];
回答(1 个)
Ameer Hamza
2020-6-17
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!