You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Meaning of the symbol '' \ ''
296 views (last 30 days)
Show older comments
Hi,
I am trying to understand a pre written matlab code. There is a line: dx = -(J \ F);
What does the forward slash mean? Does it mean F divided by J or something?
Accepted Answer
Lukas Bystricky
on 28 Jul 2015
Edited: Lukas Bystricky
on 28 Jul 2015
That's actually a backward slash. J\F is equivalent to solving the system J dx = F for dx, where J is a matrix (probably a Jacobian) and F and dx are vectors.
16 Comments
Waqas Syed
on 28 Jul 2015
Yeah its a backslash. My bad.
So both back and forward slashes imply division but with opposite directions?
Stephen23
on 28 Jul 2015
Edited: Stephen23
on 28 Jul 2015
@Waqas Syed: there is no significant difference apart from the order, which matches the order linear equation system that it solves. According to the documentation:
- mldivide "Solve systems of linear equations Ax = B for x"
- mrdivide "Solve systems of linear equations xA = B for x"
The two operators mldivide and mrdivide both solve systems of linear equations, and can both be used to divide by scalars. The documentation also notes that "The operators / and \ are related to each other by the equation B/A = (A'\B')'."
Kenny
on 30 Jun 2020
This is/was a great question about that backslash character. When we have Ax = B, and we use A\B to solve for 'x', it just seems to me for all these years, that the backslash symbol has been lost in translation, or just never taught properly about what it actually means - such as - we know it is a codeword for solving for x here. But could it have been better to have coded it as B\A instead? That is if Ax = B (matrix equation), then 'intuitively', one would picture in their mind x = B/A (which isn't allowed, since we're not doing basic division here), so B\A would have been a nice alternative. On the other hand, if we write x = A^(-1).B, which is A_inverse times B, then I could picture the \ symbol as an inverse operator ---- such as 'A\' interpreted as 'inverse of A' (even though that's not how it works). The reason behind mentioning all this is just due to having never understood whether the operator \ has more of a meaning that just rope-learning A\B for solving Ax = B.
Christine Tobler
on 30 Jun 2020
Think of the direction of the backslash as telling you which is the "numerator" vs. the "denominator" - like a fraction which maintains a sense of direction. Because we're using matrices,
A \ B = inv(A) * B
and
B / A = B * inv(A)
are not the same thing. If we're using scalars, the two are exactly the same, because of commutativity: a*b = b*a for scalars, therefore inv(a)*b = b*inv(a) and a \ b = b / a.
Having a fraction
with two matrices, on the other hand, would not make sense, since this must be a matrix multiplication and we therefore must know who's on the left and who's on the right. So the backward / forward slash can be pictured as a way to specify who's being inverted (the one "below" the line) and on which side of the multiplication both matrices are.
This is all talking about mathematical intuition, of course. The algorithm underneath mldivide does not compute an inverse but instead solves the linear system directly, which is much preferrable for both accuracy and speed.
Jeong Cheol Park
on 30 May 2021
I don's use the backslash to calculate the inverse matrix because it doesn't work for complex numbers.
"A\B is not alway equal to inv(A)*B"
Walter Roberson
on 31 May 2021
Could you give an example? Testing seems to indicate that the two are equivalent to within round-off error.
format long g
A = complex(randn(5,5), randn(5,5))
A =
0.000992623799124492 + 0.0560829640495359i -0.905381318777621 - 0.398393560374225i 0.700377093990676 - 0.862124510784948i 0.404304943943166 - 0.958126231680329i -0.890974479421001 - 0.621663836656907i
-1.9302742743487 + 0.406700314684335i -0.304220505361875 - 0.811612857394268i 0.651108834598317 - 0.230628781469304i -0.0444221267375187 - 1.30394069512746i -1.70637813489689 + 1.36627116598296i
0.0164551669159734 + 0.528580646281319i 0.706575845098412 - 1.50266720293766i -0.769410875922517 + 0.141780402125759i -0.682477282104919 + 1.32055793476325i -2.1534998275902 + 0.799074214788328i
-1.10561081495984 + 1.19076502024226i 0.599408664135243 - 0.113702650020593i -1.20756535401639 + 1.81944185552293i -0.459403598927519 + 0.316798408043163i 0.934795804814805 + 0.738804986955679i
-0.480841862945596 + 0.217646340463854i 0.0147301249197675 - 0.246444159536535i 1.59613276808549 + 0.699415876558451i -1.57319944252273 + 0.112913838851912i 0.788541640989461 + 0.48711745728954i
B = complex(randn(5,1),randn(5,1))
B =
-0.20671001769678 - 0.721019480051865i
-0.613706996033907 - 0.0545996685571732i
-0.669498867822517 + 1.22665047948491i
1.06282581209151 - 0.43106669371497i
0.894215103837536 + 1.41339741033932i
C = A\B
C =
-0.981249160199436 + 0.466090069260794i
-1.21058068247188 + 0.473613281424541i
-0.304857696301016 - 0.125681359475334i
-0.307334851145085 - 0.808043204705325i
0.638459642251516 + 0.522575122891811i
D = inv(A)*B
D =
-0.981249160199436 + 0.466090069260794i
-1.21058068247188 + 0.473613281424541i
-0.304857696301016 - 0.125681359475334i
-0.307334851145085 - 0.808043204705325i
0.638459642251515 + 0.522575122891811i
E = C-D
E =
-1.11022302462516e-16 + 0i
2.22044604925031e-16 + 0i
5.55111512312578e-17 - 1.11022302462516e-16i
0 + 3.33066907387547e-16i
3.33066907387547e-16 + 0i
F = sum(E(:).^2)
F =
5.23852944873328e-32 - 1.23259516440783e-32i
Jeong Cheol Park
on 31 May 2021
@Walter Roberson I am sorry that it was not about the general case of complex numbers. But if a matrix is close to singular (not exactly singular, det(A) was 10^-5 level), the blackslah operator gives different restuls from what has obatined from inv().
A\B was not the same as inv(A)*B.
A^-1*B was the same as inv(A)*B.
I have lost my calculation example for this.
Walter Roberson
on 31 May 2021
When a matrix is close to singular, inv(A)*B is less accurate than A\B
Michael Hodgson
on 14 Sep 2021
Then why just write a usual and more logical "F/J"?
And why when I do that in Matlab do I get an error?
John D'Errico
on 14 Sep 2021
@Michael Hodgson - The answer to your question is explained in great detail in the comments to this answer. READ THEM, since they tell you the difference, and what each means.
Walter Roberson
on 14 Sep 2021
Edited: Bruno Luong
on 1 Oct 2021
"The operators / and \ are related to each other by the equation B/A = (A'\B')'."
So J\F vs F/J would only be the same if F and J are each real and symmetric.
Kriti Salwan
on 1 Oct 2021
Edited: Bruno Luong
on 1 Oct 2021
What happens if we are applying backlash to a matrix whichis not square ?
Bruno Luong
on 1 Oct 2021
Not true
J=rand(3); J=J+J',
J = 3×3
0.0670 0.8628 0.2369
0.8628 1.6893 1.1714
0.2369 1.1714 1.6260
F=rand(3); F=F+F',
F = 3×3
0.8988 0.3888 0.1346
0.3888 0.2691 0.9150
0.1346 0.9150 1.4615
J\F
ans = 3×3
-1.1987 -1.0761 -0.0648
1.3265 0.4196 -0.1101
-0.6982 0.4172 0.9877
F/J
ans = 3×3
-1.1987 1.3265 -0.6982
-1.0761 0.4196 0.4172
-0.0648 -0.1101 0.9877
Bruno Luong
on 1 Oct 2021
Edited: Bruno Luong
on 1 Oct 2021
x = A\b;
For A with rank(A) < size(A,2) see https://blogs.mathworks.com/cleve/2021/04/28/solving-commodious-linear-systems/
Otherwise it's a least square solution
x = argmin(norm(A*x-b))
or equivalently
x = pinv(A)*b
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)