elemental wise function of any kind not functioning
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
When I attempted to use .*, .^, .^/, none of them worked as they're supposed to. Below is the code and the answer it gave:
---------------------------------------------------------------------- Code
C = [ 0.01 0.02 0.04 0.05 0.1 ];
kappa = [ 0.01418 0.0207 0.0291 0.0327 0.0459 ];
Ac = kappa./(39.05.*10^(-3))*10^(-3)
Ka = Ac.*Ac./(C-Ac);
pKa = -log(Ka)
----------------------------------------------------------------------- What it gave
Ac =
0.0004 0.0005 0.0007 0.0008 0.0012
Ka =
1.0e-04 *
0.1368 0.1443 0.1415 0.1426 0.1398
-------------------------------------------------------------------------- End
As you can see, Ka is not what it should be. Just typing in Ac.^2 gave us
ans =
1.0e-05 *
0.0132 0.0281 0.0555 0.0701 0.1382
Which is simply not correct. How do I fix this error so I can actually use matlab again?
4 Commenti
Walter Roberson
il 17 Mag 2022
format long g
sqrt(0.0132e-5)
Notice that 0.00036 rounds to 0.0004 to four digits. Your actual data is not exactly 4/10000, it is only being rounded to that value for display purposes because you have "format short" in effect.
Stephen23
il 18 Mag 2022
Modificato: Stephen23
il 18 Mag 2022
"0.0132*10^-5. Anything that is 4^2 no matter the decimal should not have the numbers 132 as an answer, only 16"
You are confusing how data are displayed with what data are actually stored in memory. Lets have a look:
C = [ 0.01 0.02 0.04 0.05 0.1 ];
kappa = [ 0.01418 0.0207 0.0291 0.0327 0.0459 ];
Ac = kappa./(39.05.*10^(-3))*10^(-3)
Ac(1)
The value is 0.0004 when displayed with four fractional digits. The value is 3.6312e-4 when displayed using exponent notation and five significant digits. Neither is more "correct" or "better" than the other, they are both just different ways of displaying the same value. The actual value stored in memory is of course neither of those, but you can display something closer:
fprintf('%.50f\n',Ac(1))
Or show the exact value as hexadecimal:
num2hex(Ac(1))
If you want to see the value as decimal, download NUM2STREXACT here:
"But that doesn't seem to be the case here"
It is the case here.
Numeric computations use numeric data types which are displayed with a finite precision which is usually less than their stored precision. Do not confuse the displayed digits with the actual numeric (binary) value stored in memory.
Risposte (1)
Walter Roberson
il 17 Mag 2022
Give the command
format long g
and try again. You have format short in effect by default. format does not change the answer, just how the answer is displayed.
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!