- ./ rdivide, described as "Right array division".
- / mrdivide, described as "Solve systems of linear equations"
difference ./ and / with constant
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I've noticed something strange and I want to understand why this is the way it is. Simple example: take a random matrix A = [0.1234;0.5678;0.9012], the I divide this by the same constant c = 1.225 in two ways: ./ (right array division) and / (regular division).
B = A ./ c
C = A / c
The result they each give seems the same (at first glance):
0.1007
0.4635
0.7357
But when I use a simple loop (see further) to determine the number of significant digits after the comma, so before the trailing zeros, they are not the same. The last logical test with the round functions that passes is:
N = 15;
round(B(1,1),N) == C(1,1)
Starting at N = 14 and lower, the logic test fails. So this means that one of both operators (I'm guessing the ./) fixes the significance at 14 digits after the comma.
My question: Why is this and how do I get around this?
Loop to determine the significance:
function [ sigdig ] = signDig( commaNumber )
% Find the significant digits after the comma
% » count backwards to finish with the smallest N value possible
% » till -100 included
% Interpretation:
% N > 0: significanct to N digits to the right of the decimal point.
% N = 0: significanct to the nearest integer.
% N < 0: significanct to N digits to the left of the decimal point.
% If array, it will loop all commaNumbers and return the max significance
% If single value, it will return the sign of that value
for i = 1:length(commaNumber)
for N = 100:-1:-100
if round(commaNumber(i),N) == commaNumber(i)
sigdig(i,1) = N;
end
end
end
sigdig = max(sigdig);
end
1 commentaire
Stephen23
le 9 Août 2018
Modifié(e) : Stephen23
le 9 Août 2018
"./ (right array division) and / (regular division)"
Actually the functions are:
It should be pretty clear from the description which one you want to use: if you are not solving equations, then right array division is better, simply because it makes the intent of your code clearer.
The differences between array and matrix operations are described here:
In general if you are not doing linear algebra then you should be using the dotted operators.
Note the mrdivide documentation states clearly that "If A is a scalar, then B/A is equivalent to B./A".
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!