이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Meaning of the symbol '' \ ''
조회 수: 312 (최근 30일)
이전 댓글 표시
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?
채택된 답변
Lukas Bystricky
2015년 7월 28일
편집: Lukas Bystricky
2015년 7월 28일
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
Waqas Syed
2015년 7월 28일
Yeah its a backslash. My bad.
So both back and forward slashes imply division but with opposite directions?
Stephen23
2015년 7월 28일
편집: Stephen23
2015년 7월 28일
@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
2020년 6월 30일
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
2020년 6월 30일
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
2021년 5월 30일
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
2021년 5월 31일
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
2021년 5월 31일
@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.
Stephen23
2021년 5월 31일
@Jeong Cheol Park: I would not expect them to be the same: mldivide is numerically much more robust.
Michael Hodgson
2021년 9월 14일
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
2021년 9월 14일
@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
2021년 9월 14일
편집: Bruno Luong
2021년 10월 1일
"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
2021년 10월 1일
편집: Bruno Luong
2021년 10월 1일
What happens if we are applying backlash to a matrix whichis not square ?
Bruno Luong
2021년 10월 1일
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
2021년 10월 1일
편집: Bruno Luong
2021년 10월 1일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)