What is the difference between backward slash vs forward slash in MATLAB?
294 views (last 30 days)
I have a failry simple question in MATLAB. What s the difference between the backslash operator vs the forward slash operator. For example,
x1 = A/b;
%which is different from:
x2 = A\b;
I am asking because I am trying to convert a simple line of code from MATLAB to c++ which it turns out there's no forward slash in c++ unfortunately.
William Rose on 20 Jun 2022
X=A\B computes X=inv(A)*B.
Y=A/B computes Y=A*inv(B)
When I look at A\B, I try to remember that the A looks like it is "under" the divide sign, which reminds me that A is the denominator in A\B. And it comes first, so inv(A) is before B in the (non-commutative) multiplication.
More Answers (2)
John D'Errico on 20 Jun 2022
BOTH of them are linear algebraic solutions. Where matrices are involved, they solve subtly different problems.
A\b solves the linear algebra problem A*X=b.
For these matrices...
X1 = A\b
Did it work?
Did it recover the matrix b? Yes.
What does forward slash do? Again, when matrices are involved, it solves a different problem. A/b is equivalent to solving the linear algebra problem X2*b=A.
X2 = A/b
Did it work?
Essentially, the two are similar in philosophy. The difference is where the unknown matrix would be in the problem you are implicitly solving.