How can I solve a system in complex variables ?
Mostrar comentarios más antiguos
Hi everyone,
I am founding lot of problem in solving a system in the form A*a - B*b=0 where A and B are matrices and a and b vector columns, where inside A and B I have got my complex unknowns; the number of unknowns match the number of equations, but the problem is that the unknown are inside the matrices and I am not able to simplify the problem. To call the complex unknown I have used the sym function, and to solve the problem respect to my functions I have used the comand "solve()". I report my system below: as you can see the only unknowns are G and N1, while s B C g are terms that depends upon these unknowns. Once defined these terms I have defined my matrices and vectors (the vectors are compose by known values).
for x1=(0:0.1:1);
for x2=(1.1:0.1:2);
G = sym('G');
N1 = sym('N1');
beta_s= (mi)/ro_s;
beta_l= (-i*om*G)/ro_l;
s_s= N1/beta_s;
s_l= N1/beta_l;
B_s= sqrt(1-beta_s^2*s_s^2);
B_l= sqrt(1-beta_s^2*s_s^2);
C_s= 1-2*beta_s^2*s_s^2;
C_l= 1-2*beta_l^2*s_l^2;
g_s= exp(i*om*B_s*beta_s^-1*x1);
g_l= exp(i*om*B_s*beta_s^-1*x2);
A1=[0
i*om*ro_s*s_s*beta_s^-1*B_s*g_s
0 -i*om*ro_s*s_s*beta_s^-1*B_s*g_s;
0
i*om*ro_s*s_s*beta_s*C_s*g_s^-1
0
-i*om*ro_s*beta_s*C_s*g_s;
0
-B_s*g_s^-1
0
B_s*g_s;...
0
-beta_s*s_s*g_s^-1
0
-beta_s*s_s*g_s];
A2=[0
i*om*ro_l*s_l*beta_l^-1*B_l*g_l
0
-i*om*ro_l*s_l*beta_l^-1*B_l*g_l;
0
i*om*ro_l*s_l*beta_l*C_l*g_l^-1
0
-i*om*ro_l*beta_l*C_l*g_l;
0
-B_l*g_l^-1 0 B_l*g_s;...
0
-beta_l*s_l*g_l^-1
0
-beta_s*s_l*g_l];
V_1=[0; Rs1;0; Ts1];
V_2=[0;0;0;Ts2];
S= solve(A1*V_1-A2*V_2);
end
end
In the end I come out with this error
??? Error using ==> maple at 129
at offset 480, `;` unexpected
Error in ==> sym.findsym at 33
v = maple('indets', sc ,'symbol');
Error in ==> solve at 99
vars = ['[' findsym(sym(eqns),neqns) ']'];
Error in ==> sym.solve at 49
[varargout{1:max(1,nargout)}] = solve(S{:});
Error in ==> xxx at 39
S=solve(A1*V_1-A2*V_2);
So my question is: is there a way to solve this kind of problem in Matlab? Can I obtain an explicit expression for my variable G for a certain value of x in the form G(x)= Re+Im?
Thank you very much for the help
3 comentarios
ChristianW
el 7 de Feb. de 2013
Editada: ChristianW
el 7 de Feb. de 2013
Can you reproduce the error/problem with minimal and independent code? If yes, post the code please.
The function solve gives complex solutions:
syms x
solve('x^4 + 1 = 2*x^2 - 1')
Walter Roberson
el 7 de Feb. de 2013
Please put a breakpoint in at the solve() call, and run, and when it stops, please show us the values of A1, V_1, A2, V_2, and A1*V_1-A2*V_2
Michele
el 11 de Feb. de 2013
Respuesta aceptada
Más respuestas (3)
Miroslav Balda
el 7 de Feb. de 2013
Maybe that you can get a solution in a simpler way just in MATLAB without using symbolic approach. Your equation is complex dependent on a complex vector p composed out of 2 complex unknowns G and N1. The solution can be obtained by the following (pseudo)code:
p0 = [real(G0);real(N10); imag(G0); imag(N10)]; % initial estimates of unknowns
[p,ssq,cnt] = LMFnlsq(@res, ones(size(p0)), 'Display',-10);
% LMFnlsq in FEX at www.mathworks.com/matlabcentral/fileexchange/17534
p = p.*p0;
% The solution:
G = complex(p(1),p(3))
N1 = complex(p(2),p(4))
fprintf('Sum of squares = %10.2e\n...
'Function evaluations %g\n...
'G = %10.2e + %10.2ei\n...
'NI = %10.2e + %10.2ei\n', ssq, cnt, p(1),p(3), p(2),p(4));
It is neccessary to build the function for evaluating differences of the given matrix equation from zero:
function r = res(p)
p = p.*p0;
G = complex(p(1),p(3))
N1 = complex(p(2),p(4))
% Evaluate a complex residual d between the equation and zero as
% d = A(p)*a(p)-B(p)*b(p); % and set the vector of its components:
r = [real(d); imag(d)]; % residuals
As is obvious, it is necessary to solve a system of 2 equations for 2 complex unknowns.
2 comentarios
Miroslav Balda
el 7 de Feb. de 2013
More rigorous would be to write d = A(q)*a(q)-B(q)*b(q), where
q = [G;N1]; instead of d = A(p)*a(p)-B(p)*b(p) in the function res.
Michele
el 11 de Feb. de 2013
Michele
el 11 de Feb. de 2013
0 votos
Categorías
Más información sobre Linear Least Squares en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!