Is this a symbolic math bug?
Afficher commentaires plus anciens
1. Let's a=log(2), I want create with only 5 digits:
>>digits(5);b=sym(a,'d')
b = 0.69315
But what is another way? This way isn't good while - by command digits I effect global changes -- and I am forced to return: digits(32)
2. Perhaps one wants to include periodic ratio Suppose a working example: >> b=sym(0.69696969696969,'r') true result 69/99=23/33, but many signs are needed -- on contrary: >> b=sym(0.6969,'r') b = 6969/10000
How to easy include, for example, 1.23(45) as ratio?
3. >> syms x positive;
>> x=solve('y=-1')
x = -1
But why was quiet reaction? How to clarify the attribute "positive" (in order to machine feel)?
4. And critical and scandal bug:
>> sym(0.6915 - 0.69,'d')
ans = 0.0015000000000000568434188608080149
at this: >>0.6915000-0.69
ans = 0.001500000000000
and also you may see:
>> sym(0.6915 - 0.69,'r')
ans = 211106232533/140737488355328
>> 211106232533/140737488355328
ans = 0.001500000000000
instead of sholar simple 15/10000
4 commentaires
Andrew Newell
le 9 Fév 2011
@Igor - In point 1, do you want to simply display log(2) to 5 digits or set b equal to log(2) rounded to 5 digits?
Andrew Newell
le 9 Fév 2011
I don't understand question 2.
Doug Hull
le 9 Fév 2011
It is a best practice to post ONE question per question. It keeps things orderly.
James Tursa
le 9 Fév 2011
This is the decimal representation of the exact value you are using:
>> num2strexact(0.6915 - 0.69)
ans =
1.50000000000005684341886080801486968994140625e-3
The fact that MATLAB only displays 15 significant decimal digits of this does not mean that the underlying number is exactly the displayed result.
Réponse acceptée
Plus de réponses (1)
Andrew Newell
le 9 Fév 2011
I think what you want in question 1 is
b = vpa(log(sym('2')),5);
For question 3, x should be the variable in SOLVE:
syms x positive
x = solve('x=-1',x)
For question 4, try
vpa(sym('0.6915')-sym('0.69'),5)
ans =
0.0015
To get the right answer for the fraction, use:
vpa(sym('211106232533/140737488355328'))
You were calculating it in double precision, which isn't accurate enough.
EDIT: I have incorporated a couple of suggestions from @Walter and another from @James.
2 commentaires
Walter Roberson
le 9 Fév 2011
Andrew, you are letting things be evaluated by Matlab in double precision before having them pass in to the symbolic engine.
b = vpa(log(sym('2')),5);
vpa(sym('211106232533/140737488355328'))
Andrew Newell
le 9 Fév 2011
Good point, @Walter. I prefer doing my symbolic calculations directly in Maple - fewer pitfalls.
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!