Quick question on understanding ./ notation

2 次查看(过去 30 天)
Greetings all,
I have the following "snippet" of code:
Zeta_EM31_West = DrillHoleData2(:,3)/3.67;
%Line above outputs a 16x1 double array, I can provide "DrillHoleData2" if needed
Response_values_H= 0:0.01:9;
R_h=sqrt(4*Response_values_H.^2+1)-(2*Response_values_H);
R_h(Response_values_H>=9.1) = 0;
R_h_Case1A=interp1(Response_values_H,R_h,Zeta_EM31_West);
Now I'm a bit confused on something. Say the next line is this: sigma_2_Case1A=EM31CondMidSwathWest/R_h_Case1A;
where "EM31CondMidSwathWest" is another 16x1 array (and I can provide the numbers if needed). Now just using / will provide me with a 16x16 double, which I understand, but in one column I'll receive values, and the rest are zeros (I also understand this).
What I don't understand is if I say: sigma_2_Case1A=EM31CondMidSwathWest./R_h_Case1A;
which will be a 16x1 double, but the numbers will be different than those with using "/". Shouldn't they be the same?
Thanks! -J

采纳的回答

John D'Errico
John D'Errico 2015-5-19
编辑:John D'Errico 2015-5-19
If they should be the same for / and ./ I imagine they would not give us TWO different operators?
./ does an element-wise division. It divides each element by the corresponding element, as long as the two vectors/arrays are the same size and shape. It will fail if they are not, unless one of them was a scalar.
/ does the element-wise division IF the denominator is a scalar. If the two arguments are arrays, or vectors, then linear algebra comes into play.
B/A is equivalent to B*inv(A), WHEN A is a square matrix. If A is not a square matrix, then a solve is done that employs a factorization of the matrix A.
READ THE HELP. Of course, I admit that it might not be obvious to look at these:
help slash
help rdivide
help ldivide
help mrdivide
After all, I might have naively looked for help under divide. I honestly think it would be a good idea if this:
help divide
produced links to the appropriate functions, and explained the basic differences between all of those operators.
  3 个评论
Jesse
Jesse 2015-5-19
John, thanks for your help. Apologies for asking such a basic question, but stepping away from my code for a couple of hours gave me an "a-ha" moment. Sometimes we all need that!

请先登录,再进行评论。

更多回答(1 个)

the cyclist
the cyclist 2015-5-19
I'm not as confident as you are that you understand the difference between the rdivide (./) and mrdivide (/). In particular, the latter command is for solving systems of linear equations, not for simple division.
I suggest you read those documentation pages carefully.
You can read more generally about array vs. matrix operations here.

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by