Is this a symbolic math bug?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Doug Hull
2011 年 2 月 9 日
It is a best practice to post ONE question per question. It keeps things orderly.
James Tursa
2011 年 2 月 9 日
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.
採用された回答
Igor
2011 年 2 月 10 日
3 件のコメント
Andrew Newell
2011 年 2 月 10 日
Igor, can you please make a new question for each of these issues? This sprawling post is hard to deal with.
James Tursa
2011 年 2 月 10 日
In the case of (0.5-0.8) the sym function is trying to "guess" what you meant by the input. Again, the input is not exactly 0.3, it is:
>> num2strexact(0.5-0.8)
ans =
-0.3000000000000000444089209850062616169452667236328125
So in this case it guessed that you really wanted an exact 0.3 result even though the input was *not* exactly 0.3. But in the other case:
>> num2strexact(0.6915 - 0.69)
ans =
1.50000000000005684341886080801486968994140625e-3
the sym function just wasn't clairvoyant enough to guess what you wanted for a result. Don't blame syms for being "wrong" just because it didn't guess what you wanted as well as you had hoped. Reformulate your code properly instead.
その他の回答 (1 件)
Andrew Newell
2011 年 2 月 9 日
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 件のコメント
Walter Roberson
2011 年 2 月 9 日
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
2011 年 2 月 9 日
Good point, @Walter. I prefer doing my symbolic calculations directly in Maple - fewer pitfalls.
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!