Return if No Solution
Mostrar comentarios más antiguos
I am asked to solve the equation: Ax = B for two randomly generated matrices. Furthermore, I am instructed that the script should return if no solution is found.
Here is my code:
n=100;
A=randn(n);
B=randn(n);
x = A\B;
I believe I know how to solve the equation, but don't know how to return if no solution is found. Is there a different way that I should be writing this? If not, how to I return if no solution is found?
1 comentario
the cyclist
el 13 de Sept. de 2019
Can you be more specific as to what you mean by "no solution"?
Do you mean if
x = A\B;
returns an error message, or something else?
Respuesta aceptada
Más respuestas (1)
David Hill
el 13 de Sept. de 2019
0 votos
If A will always be a square matrix, then if the det(A)==0 then return (no solution).
1 comentario
Walter Roberson
el 13 de Sept. de 2019
det()==0 is not as good a test as rank() because det() is more prone to round-off error.
Categorías
Más información sobre Numeric Solvers 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!