Extract positive value from solve function

32 visualizaciones (últimos 30 días)
Sashi Mendoza
Sashi Mendoza el 3 de Abr. de 2022
Editada: Sashi Mendoza el 21 de Abr. de 2022
eqs = [(A-a1) == d, (A-a2) == d2;
S = solve(eqs, [A B]);
a = S.A
b = S.B
In the code above, all other variables are given so i AM solving for A and B. The code above alrEADY works and displays a solution but how will I extract the positive values of the solution only , and assign them to variables a and b?

Respuestas (1)

Torsten
Torsten el 3 de Abr. de 2022
Editada: Torsten el 3 de Abr. de 2022
If a and b contain no more symbolic constants, then you can use
a = double(a);
b = double(b);
a = a(abs(imag(a)) < 1e-6);
b = b(abs(imag(b)) < 1e-6);
a = real(a);
b = real(b);
A = [];
B = [];
iter = 0;
for i = 1:numel(a)
if a(i) >= 0 && b(i) >= 0
iter = iter + 1;
A(iter) = a(i);
B(iter) = b(i);
end
end
A
B
  2 comentarios
Sashi Mendoza
Sashi Mendoza el 3 de Abr. de 2022
Editada: Sashi Mendoza el 3 de Abr. de 2022
I tried inputting this, but hte code still yields 2 answers each for A and B
A =
0.8465 + 0.3307i
0.8465 - 0.3307i
B =
0.4579 - 0.2660i
0.4579 + 0.2660i
Torsten
Torsten el 3 de Abr. de 2022
Editada: Torsten el 3 de Abr. de 2022
Since you get complex solutions to your system, the two circles don't cross for the midpoints and radii given.
In order that they have points in common, the condition
d + d2 >= sqrt((a1-a2)^2 + (c1-c2)^2)
must be met.
I modified the code from above.

Iniciar sesión para comentar.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by