Message Boards Message Boards

GROUPS:

[✓] Is there one term missing when using Table?

Posted 1 year ago
2673 Views
|
6 Replies
|
5 Total Likes
|

Hey guys:

When I use "Table" to get a series calculation results for A from 0 to 1 with gap 0.1. So there should be 11 elements in the list at last while "Table" only gives me 10 results and miss the last one when A=1. Really appreciate someone can tell me what happened and how to improve this. You may also find the commands in the attachment.

$PreRead = (# /. 
     s_String /; 
       StringMatchQ[s, NumberString] && 
        Precision@ToExpression@s == MachinePrecision :> s <> "`50." &);
skew[A_, \[Alpha]_, \[Beta]_, \[Delta]_] = (2 Sqrt[\[Delta]] (((-1 + 
            A) A (\[Alpha] - \[Beta])^2 (A^2 (\[Alpha] - \[Beta])^2 - 
            A (\[Alpha] - \[Beta]) (\[Alpha] - \[Beta] - \[Delta]) + \
\[Beta] (\[Alpha] + \[Delta])) (-(-1 + 
                A) \[Beta] \[Delta] + \[Alpha] (\[Beta] + 
               A \[Delta])))/(((-1 + A) \[Alpha] - A \[Beta] - 
            3 \[Delta]) ((-1 + A) \[Alpha] - A \[Beta] - 
            2 \[Delta]) (\[Alpha] - A \[Alpha] + 
            A \[Beta] + \[Delta])^3) + (-3 (-1 + 
           A) \[Beta] \[Delta] + \[Alpha] (\[Beta] + 
           3 A \[Delta]))/(\[Alpha] - A \[Alpha] + A \[Beta] + 
        3 \[Delta]) - ((-1 + 
          A) A (\[Alpha] - \[Beta])^2 (-3 (-1 + 
             A) \[Beta] \[Delta] + \[Alpha] (2 \[Beta] + 
             3 A \[Delta])))/((\[Alpha] - A \[Alpha] + 
          A \[Beta] + \[Delta]) (\[Alpha] - A \[Alpha] + A \[Beta] + 
          2 \[Delta]) (\[Alpha] - A \[Alpha] + A \[Beta] + 
          3 \[Delta]))))/(((-1 + 
        A) A (\[Alpha] - \[Beta])^2 (-(-1 + 
            A) \[Beta] \[Delta] + \[Alpha] (\[Beta] + 
           A \[Delta])))/(((-1 + A) \[Alpha] - A \[Beta] - 
        2 \[Delta]) (\[Alpha] - A \[Alpha] + 
        A \[Beta] + \[Delta])^2) + (-2 (-1 + 
         A) \[Beta] \[Delta] + \[Alpha] (\[Beta] + 
         2 A \[Delta]))/(\[Alpha] - A \[Alpha] + A \[Beta] + 
      2 \[Delta]))^(3/2);
Table[skew[A, 20.1, 2.98, 0.015], {A, 0, 1, 0.1}] // N
Length[%]

{0.141895, 0.139203, 0.135927, 0.131859, 0.126677, 0.11985, 0.110442, \
0.0966346, 0.0744006, 0.033185}

10

Thanks in advance

Attachments:
6 Replies

0.1 is never really 0.1 in binary representation:

Table[A, {A, 0, 1, 0.1`50}]

if you copy the last number you will see:

0.90000000000000000000000000000000000000000000000000000000000000000000000000003`50.

i.e. a little bit more than 0.9, use exact arithmetic to be sure it is 11, or use Subdivide:

Table[A, {A, Subdivide[0, 1, 10]}]

Perhaps it's because if you sum ten instances of .1`50. you get someting slightly more than 1:

In[2]:= .1`50. + .1`50. + .1`50. + .1`50. + .1`50. + .1`50. + .1`50. \
+ .1`50. + .1`50. + .1`50. // FullForm

Out[2] 1.0000000000000000000000000000000000000000000000000000000000000000000000\
0000003`50.
Posted 1 year ago

Hint

In[1]:= ...
Length[Table[skew[A, 20.1, 2.98, 0.015], {A, 0, 1, 0.1}]]

Out[3]= 10

versus

In[1]:= ...
Length[Table[skew[A, 20.1, 2.98, 0.015], {A, 0, 1, 1/10}]]

Out[3]= 11
Posted 1 year ago

Sorry, I still do not what is happening here. I set up a table for k from 1 to 2 with gap 0.1. It turns out that the results are the same no matter gap being 0.1 or 1/10. Please see more details in the attachment.

Attachments:

Just to clarify, this is the normal behavior

In[7]:= Length@Table[x, {x, 0, 1, .1}]

Out[7]= 11

When you do something drastic like

$PreRead = (# /. 
     s_String /; 
       StringMatchQ[s, NumberString] && 
        Precision@ToExpression@s == MachinePrecision :> 
      s <> "`50." &);

then you need to be ready for the consequences, among which is

In[10]:= Length@Table[x, {x, 0, 1, .1}]

Out[10]= 10

Since you want your answers to such a high number of digits, why not just keep everything as rational and use N at the end?

skew[Amp_, αmp_, βmp_, δmp_] := 
  Module[{A = Rationalize@Amp, α = 
     Rationalize@αmp, β = 
     Rationalize@βmp, δ = 
     Rationalize@δmp}, (2 Sqrt[δ] (((-1 + 
             A) A (α - β)^2 (A^2 (α - β)^2 -
              A (α - β) (α - β - δ) \
+ β (α + δ)) (-(-1 + 
                 A) β δ + α (β + 
                A δ)))/(((-1 + A) α - A β - 
             3 δ) ((-1 + A) α - A β - 
             2 δ) (α - A α + 
             A β + δ)^3) + (-3 (-1 + 
            A) β δ + α (β + 
            3 A δ))/(α - A α + A β + 
         3 δ) - ((-1 + 
           A) A (α - β)^2 (-3 (-1 + 
              A) β δ + α (2 β + 
              3 A δ)))/((α - A α + 
           A β + δ) (α - A α + A β + 
           2 δ) (α - A α + A β + 
           3 δ))))/(((-1 + 
         A) A (α - β)^2 (-(-1 + 
             A) β δ + α (β + 
            A δ)))/(((-1 + A) α - A β - 
         2 δ) (α - A α + 
         A β + δ)^2) + (-2 (-1 + 
          A) β δ + α (β + 
          2 A δ))/(α - A α + A β + 
       2 δ))^(3/2)
   ];

In[2]:= Table[skew[A, 20.1, 2.98, 0.015], {A, 0, 1, 0.1}] // N[#, 50] &
Length[%]

Out[2]= {0.14189513095212063367049531962987546141568326643434, \
0.13920344101328578263969756404215809382766534147239, \
0.13592716321563841983794812006874993948237693570027, \
0.13185917327785972103954298320739470452252943280392, \
0.12667686295955584799447506972227890015016781166517, \
0.11984973711991386295060361312735642563028850992476, \
0.11044152395284289944251345711595700385738865557709, \
0.096634643366104288816678293713331415198513960340867, \
0.074400586745371447280910852144971096789513221053062, \
0.033185045336993739355804248832880796377132424223379, \
0.054635836470815303531952862734950163493012524454082}

Out[3]= 11
Posted 1 year ago

Thank you guys. Your comments answered my question well and I have learned a lot.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract