現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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.
Walter Roberson
2021 年 5 月 31 日
When a matrix is close to singular, inv(A)*B is less accurate than A\B
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)