equationsToMatrix output defaults to negative

3 visualizaciones (últimos 30 días)
Adam Darcie
Adam Darcie el 11 de Mayo de 2021
Respondida: Shantanu Dixit el 11 de Sept. de 2024
I'm trying to use "equationsToMatrix" to put a system of symbolic equations into matrix form, but I'm getting the negative of what I want.
For example I have two vectors:
x1=[a1;b1;c1;d1];
x2=[a2;b2;c2;d2];
And I want to convert the following into the form x2=A*x1:
m = [a1*exp((R*pi*(alpha_ccw/2 + beta*1i))/2);
b1*exp(-(R*pi*(alpha_ccw/2 + beta*1i))/2);
c1*exp((R*pi*(alpha_cw/2 - beta*1i))/2);
d1*exp(-(R*pi*(alpha_cw/2 - beta*1i))/2)]
So I use:
[Cprop_bottom,b] = equationsToMatrix(x2==m,x1)
I get the right answer but the negative. Essentially it says that both 'b' and 'Cprop_bottom' are negative so the solution is still true but not expected.
Am I doing something wrong? I could work around it by subsituting one of the 'b' output variables for a positive number and seeing if the result is negative, but I would prefer understand why the output defaults to negative to begin with.
Thanks in advance!

Respuestas (1)

Shantanu Dixit
Shantanu Dixit el 11 de Sept. de 2024
Hi Adam, if my understanding of the problem faced here is correct then the issue is likely due to the way the equations are being interpreted when using 'equationsToMatrix'. The function solves for the coefficients in a linear system, and coeffecients can be factored.
As both 'b' and 'Cprop_bottom' are negative essentially means the same solution. One possible workaround would be to normalize/simplify the equations (using 'simplify')
Refer to the below example code using 'equationsToMatrix':
syms a1 b1 a2 b2
e1 = -2*a1 - 3*b1 == -5;
e2 = -4*a1 - 5*b1 == -7;
[A, b] = equationsToMatrix([e1, e2], [a1, b1]);
disp('Matrix A:');
Matrix A:
disp(A);
disp('Matrix B:');
Matrix B:
disp(b);
e1 = simplify(e1);
e2 = simplify(e2);
[A, b] = equationsToMatrix([e1, e2], [a1, b1]);
disp('Matrix A:');
Matrix A:
disp(A);
disp('Matrix B:');
Matrix B:
disp(b);
Additionally you can refer to the MathWorks documentation of 'equationsToMatrix' and 'simplify':

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by