Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Numerical approximation - Newbie question

Hi. I'm new to SAGE and to computational mathematics in general. I have been trying to code something, but I am struggling to understand some numerical approximation errors. My problem seems to boil down to the following phenomenon:

sage: x = exp(12*pi*i*i)
sage: x.n()
0.000000000000000

Which is as expected, $x=e^{-12\pi }$ is "very close" to 0. However, I do not understand why SAGE gives me

sage: (5+x).n()
4.00000000000000

If I give it more bits of precision, then it works:

sage: (5+x).n(200)
5.0000000000000000424115118301607754401746440550887456940681

But I can't understand why it is making such grotesque error. SAGE knows $x$ is very small (it returned 0.000000000000000). So why did it approximate $5+x$ to 4?

What is also weird, is that if I repeat the same computation with 4+x or 6+x instead, then it works just fine:

sage: (6+x).n()
6.00000000000000

My apologies if this is something trivial in computational maths, but can someone clarify what is going on here?

In a situation like this, is there a way for me to know if I have given SAGE enough bits of precision to get at least the first few digits correct?

(Remark: I wrote exp(12*pi*i*i) instead of exp(-12*pi) to make SAGE use sinh and cosh.)

Numerical approximation - Newbie question

Hi. I'm new to SAGE Sage and to computational mathematics in general. general. I have been trying to code something, but I am struggling to understand understand some numerical approximation errors. My problem seems to boil down down to the following phenomenon:

sage: x = exp(12*pi*i*i)
sage: x.n()
0.000000000000000

Which is as expected, $x=e^{-12\pi }$ is "very close" to 0. 0. However, I do not understand why SAGE Sage gives me

sage: (5+x).n()
4.00000000000000

If I give it more bits of precision, then it works:

sage: (5+x).n(200)
5.0000000000000000424115118301607754401746440550887456940681

But I can't understand why it is making such grotesque error. SAGE error. Sage knows $x$ is very small (it returned 0.000000000000000). 0.000000000000000). So why did it approximate $5+x$ to 4?

What is also weird, is that if I repeat the same computation computation with 4+x or 6+x instead, then it works just fine:

sage: (6+x).n()
6.00000000000000

My apologies if this is something trivial in computational maths, maths, but can someone clarify what is going on here? here?

In a situation like this, is there a way for me to know if I have given SAGE Sage enough bits of precision to get at least the first few digits correct?

(Remark: I wrote exp(12*pi*i*i) instead of exp(-12*pi) to make SAGE Sage use sinh and cosh.)

Numerical approximation - Newbie question

Hi. I'm new to Sage and to computational mathematics in general. I have been trying to code something, but I am struggling to understand some numerical approximation errors. My problem seems to boil down to the following phenomenon:

sage: x = exp(12*pi*i*i)
sage: x.n()
0.000000000000000

Which is as expected, $x=e^{-12\pi }$ is "very close" to 0. However, I do not understand why Sage gives me

sage: (5+x).n()
4.00000000000000

If I give it more bits of precision, then it works:

sage: (5+x).n(200)
5.0000000000000000424115118301607754401746440550887456940681

But I can't understand why it is making such grotesque error. Sage knows $x$ is very small (it returned 0.000000000000000). So why did it approximate $5+x$ to 4?

What is also weird, is that if I repeat the same computation with 4+x or 6+x instead, then it works just fine:

sage: (6+x).n()
6.00000000000000

My apologies if this is something trivial in computational maths, but can someone clarify what is going on here?

In a situation like this, is there a way for me to know if I have given Sage enough bits of precision to get at least the first few digits correct?

(Remark: I wrote exp(12*pi*i*i) instead of exp(-12*pi) to make Sage use sinh and cosh.)

Numerical approximation - Newbie question

Hi. I'm new to Sage and to computational mathematics in general. I have been trying to code something, but I am struggling to understand some numerical approximation errors. My problem seems to boil down to the following phenomenon:

sage: x = exp(12*pi*i*i)
sage: x.n()
0.000000000000000

Which is as expected, $x=e^{-12\pi }$ is "very close" to 0. However, I do not understand why Sage gives me

sage: (5+x).n()
4.00000000000000

If I give it more bits of precision, then it works:

sage: (5+x).n(200)
5.0000000000000000424115118301607754401746440550887456940681

But I can't understand why it is making such grotesque error. Sage knows $x$ is very small (it returned 0.000000000000000). So why did it approximate $5+x$ to 4?

What is also weird, is that if I repeat the same computation with 4+x or 6+x instead, then it works just fine:

sage: (6+x).n()
6.00000000000000

My apologies if this is something trivial in computational maths, but can someone clarify what is going on here?

In a situation like this, is there a way for me to know if I have given Sage enough bits of precision to get at least the first few digits correct?

(Remark: I wrote exp(12*pi*i*i) instead of exp(-12*pi) to make Sage use sinh and cosh.)

Numerical approximation - Newbie question

Hi. I'm new to Sage and to computational mathematics in general. I have been trying to code something, but I am struggling to understand some numerical approximation errors. My problem seems to boil down to the following phenomenon:

sage: x = exp(12*pi*i*i)
sage: x.n()
0.000000000000000

Which is as expected, $x=e^{-12\pi }$ is "very close" to 0. However, I do not understand why Sage gives me

sage: (5+x).n()
4.00000000000000

If I give it more bits of precision, then it works:

sage: (5+x).n(200)
5.0000000000000000424115118301607754401746440550887456940681

But I can't understand why it is making such grotesque error. Sage knows $x$ is very small (it returned 0.000000000000000). So why did it approximate $5+x$ to 4?

What is also weird, is that if I repeat the same computation with 4+x or 6+x instead, then it works just fine:

sage: (6+x).n()
6.00000000000000

My apologies if this is something trivial in computational maths, but can someone clarify what is going on here?

In a situation like this, is there a way for me to know if I have given Sage enough bits of precision to get at least the first few digits correct?

(Remark: I wrote exp(12*pi*i*i) instead of exp(-12*pi) to make Sage use sinh and cosh.)