How to solve a system of linear homogeneous equations in which the unknowns are column matrices?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Good afternoon everyone! I have a problem when I'm going to use the linsolve function to solve a system of equations, as the incognitas are column arrays of a loop I made. The error happens, I believe, because of the matrix multiplication method that is done by the linsolve function. The code does not show any errors. Anyone who can help me I would be very grateful. Here's the code:
clc
clear
% Código para calcular a dinamica do vale através das equações de taxas e
% equação mesttre com hamiltoniano usado no "Dark exciton brightening and
% its engaged valley dynamics in monolayer WSe2
B=1:1:10;
V = NaN(2,2,numel(B)); % Preallocate
D = V;
%Considerando um campo magnético no plano temos o seguinte temos
for k = 1:numel(B) ;
Dc=36 ; %(meV)
EB=10;
ED=-Dc+EB;
theta=pi/2;
phi =pi;
Bx= B(k)*sin(theta)*cos(phi);
By= B(k)*sin(theta)*sin(phi);
Bm=Bx-i*By;
Bp=Bx+i*By;
ge=2;
ub= 0.579; %(Bohr magneton em meV )
tal_r=14; %ps
tal_nr= 2,8*10^(-4) ; %ps
tal_bd=1 ; %ps
tal_bd1=(repelem(tal_bd,size(B,2)))';
H=[EB, ge*ub*Bm*0.5; ge*ub*Bp*0.5, ED];
[V(:,:,k),D(:,:,k)] = eig(H); %(RETORNA OS AUTOVALORES E AUTOVETORES DA HAMILTONIANO
end
for k = 1:size(V,3);
Gm1(:,k) = (V(:,1,k));
Gm2(:,k) = (V(:,2,k));
end
for k = 1:size(Gm1,3);
cbb(:,k)= Gm1(2,:,k) ;
end
for k = 1:size(Gm1,3);
cbd(:,k)= Gm1(1,:,k) ;
end
for k = 1:size(Gm2,3);
cdb(:,k)= Gm2(1,:,k);
end
for k = 1:size(Gm2,3);
cdd(:,k)= Gm2(2,:,k) ;
end
tal_b= ((tal_r.*tal_nr)./(tal_nr.*(abs(cbb)).^2 + tal_r.*(abs(cbd)).^2));
tal_d= ((tal_r.*tal_nr)./(tal_nr.*(abs(cdb)).^2 + tal_r.*(abs(cdd)).^2));
tal_skx=(0.03*B.*cos(theta)+1)';
tal_skxt= (tal_skx)./((abs(cbb)).^2);
tal_skd= (tal_skx)./ (abs(cdb)).^2;
g=5.35*10^(-6);
kb=8.617^(-2) ; %Constante de Boltzmann em meV/K
T=30 ; %Temperatura
u=exp(-Dc./kb*T);
syms x1 x2 x3 x4
%equações de taxas
eqn1 = g - x1./tal_b - x1./tal_skxt - x1./tal_bd1 + x3./tal_skxt + x2.*u./tal_bd1 == 0;
eqn2 = -x2./tal_d - x2*u./tal_bd1 - x2./tal_skd + x1./tal_bd1 + x4./tal_skd == 0;
eqn3 = g - x3./tal_b - x3./tal_skxt - x3./tal_bd1 + x1./tal_skxt + x4.*u./tal_bd1 == 0;
eqn4 = -x4./tal_d - x4*u./tal_bd1 - x4./tal_skd + x3./tal_bd1 + x2./tal_skd == 0;
[R,S] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [x1, x2, x3, x4]);
X = (linsolve(R,S)); % RESOLVE AS EQUAÇÕES DE TAXAS PARA dx/dt=0
0 comentarios
Respuestas (1)
Paul
el 12 de Ag. de 2022
Hi Celso
Accroding to linsolve: "If the system does not have a solution, linsolve issues a warning and returns X with all elements set to Inf." Which is exactly what's happening here. We have many equations with only four unknowns. Is there good reason to believe that a solution exists for all of these equations. If not, can convert R and S to double and use base Matlab function linsolve.
Also, is the assignment to tal_nr correct? It looks suspicious.
clc
clear
% Código para calcular a dinamica do vale através das equações de taxas e
% equação mesttre com hamiltoniano usado no "Dark exciton brightening and
% its engaged valley dynamics in monolayer WSe2
B=1:1:10;
V = NaN(2,2,numel(B)); % Preallocate
D = V;
%Considerando um campo magnético no plano temos o seguinte temos
for k = 1:numel(B) ;
Dc=36 ; %(meV)
EB=10;
ED=-Dc+EB;
theta=pi/2;
phi =pi;
Bx= B(k)*sin(theta)*cos(phi);
By= B(k)*sin(theta)*sin(phi);
Bm=Bx-i*By;
Bp=Bx+i*By;
ge=2;
ub= 0.579; %(Bohr magneton em meV )
tal_r=14; %ps
Is this line correct?
tal_nr= 2,8*10^(-4) ; %ps
tal_bd=1 ; %ps
tal_bd1=(repelem(tal_bd,size(B,2)))';
H=[EB, ge*ub*Bm*0.5; ge*ub*Bp*0.5, ED];
[V(:,:,k),D(:,:,k)] = eig(H); %(RETORNA OS AUTOVALORES E AUTOVETORES DA HAMILTONIANO
end
for k = 1:size(V,3);
Gm1(:,k) = (V(:,1,k));
Gm2(:,k) = (V(:,2,k));
end
for k = 1:size(Gm1,3);
cbb(:,k)= Gm1(2,:,k) ;
end
for k = 1:size(Gm1,3);
cbd(:,k)= Gm1(1,:,k) ;
end
for k = 1:size(Gm2,3);
cdb(:,k)= Gm2(1,:,k);
end
for k = 1:size(Gm2,3);
cdd(:,k)= Gm2(2,:,k) ;
end
tal_b= ((tal_r.*tal_nr)./(tal_nr.*(abs(cbb)).^2 + tal_r.*(abs(cbd)).^2));
tal_d= ((tal_r.*tal_nr)./(tal_nr.*(abs(cdb)).^2 + tal_r.*(abs(cdd)).^2));
tal_skx=(0.03*B.*cos(theta)+1)';
tal_skxt= (tal_skx)./((abs(cbb)).^2);
tal_skd= (tal_skx)./ (abs(cdb)).^2;
g=5.35*10^(-6);
kb=8.617^(-2) ; %Constante de Boltzmann em meV/K
T=30 ; %Temperatura
u=exp(-Dc./kb*T);
syms x1 x2 x3 x4
%equações de taxas
eqn1 = g - x1./tal_b - x1./tal_skxt - x1./tal_bd1 + x3./tal_skxt + x2.*u./tal_bd1 == 0;
eqn2 = -x2./tal_d - x2*u./tal_bd1 - x2./tal_skd + x1./tal_bd1 + x4./tal_skd == 0;
eqn3 = g - x3./tal_b - x3./tal_skxt - x3./tal_bd1 + x1./tal_skxt + x4.*u./tal_bd1 == 0;
eqn4 = -x4./tal_d - x4*u./tal_bd1 - x4./tal_skd + x3./tal_bd1 + x2./tal_skd == 0;
[R,S] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [x1, x2, x3, x4]);
%vpa(R,5),vpa(S,5)
X = (linsolve(double(R),double(S))); % RESOLVE AS EQUAÇÕES DE TAXAS PARA dx/dt=0
X
2 comentarios
Paul
el 13 de Ag. de 2022
Editada: Paul
el 13 de Ag. de 2022
Not following. The code as written generates 40 equations to solve for four unknowns, using 10 values of B. If that's not what's expected, then what is expected for 10 values of B? Maybe you're expecting 10 sets of four equations, each set with four unknowns? If that's the case, it's not clear to me based on the code what those four equations should be for each value of B.
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!