Skip to main content
Improved formatting
Source Link
Michael E2
  • 244.7k
  • 18
  • 351
  • 774

Clearly I have misunderstood how to do this: I seem unable to understand how to get more digits out of a calculation and I can't see why - the following piece of code illustrates the issue.

Block[{\[Gamma]γ, vx, vy, vz, t0, t1},
 t0 = \[Gamma]γ (t1 - vx Sin[\[Theta]]Sin[θ] Sin[\[Phi]]Sin[ϕ] - 
     vy Cos[\[Theta]]Cos[θ] Sin[\[Phi]]Sin[ϕ] - vz Cos[\[Phi]]Cos[ϕ]);
 vx = vy = vz = 0.9/Sqrt[3]; t1 = 0.;
 \[Gamma]γ = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)];
 Print[Minimize[{t0, 
    0 <= \[Theta]θ < 2 Pi, -Pi <= \[Phi]ϕ < Pi}, {\[Theta]θ, \[Phi]ϕ}, 
   Reals]];
 Print[N[Minimize[{t0, 
     0 <= \[Theta]θ < 2 Pi, -Pi <= \[Phi]ϕ < Pi}, {\[Theta]θ, \[Phi]ϕ}, 
    Reals], 30]];
 ]

Results: both print statements give

{-1.68585,{\[Theta]θ->6.28319,\[Phi]ϕ->0.7854}}

Now by semi-random fiddling I did find that changing line 4 to

vx = vy = vz = 0.9`30/Sqrt[3]; t1 = 0.;

produced plenty of digits in both print statements - but moving the backtick to after the 3 or the 0. did not have the same effect.

I naively thought that if I specified a certain precision in the calculation, Mma would work backwards and do everything necessary. How should I approach such issues?

Would somebody please enlighten me - or hit me with the stupid stick?

Update

I sitill don't have a clear rationale for this, so I am still hopeful of some insight, but I have discovered that if I were to type

Print[SetPrecision[
   Minimize[{t0, 
     0 <= \[Theta]θ < 2 Pi, -Pi <= \[Phi]ϕ < Pi}, {\[Theta]θ, \[Phi]ϕ}, 
    Reals], 30]];

then I would get

{-1.68585446084501100472152756993,
   {\[Theta]θ->6.28318530717958623199592693709,\[Phi]ϕ->0.785399718782704869823874105350}}

which is much closer to what I am trying to achieve. How do I do this for all calculations in a block or module - surely I don't have to specify this for each one?

(and why doesn't N[...., precision] achieve this result??)

Clearly I have misunderstood how to do this: I seem unable to understand how to get more digits out of a calculation and I can't see why - the following piece of code illustrates the issue.

Block[{\[Gamma], vx, vy, vz, t0, t1},
 t0 = \[Gamma] (t1 - vx Sin[\[Theta]] Sin[\[Phi]] - 
     vy Cos[\[Theta]] Sin[\[Phi]] - vz Cos[\[Phi]]);
 vx = vy = vz = 0.9/Sqrt[3]; t1 = 0.;
 \[Gamma] = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)];
 Print[Minimize[{t0, 
    0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
   Reals]];
 Print[N[Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];
 ]

Results: both print statements give

{-1.68585,{\[Theta]->6.28319,\[Phi]->0.7854}}

Now by semi-random fiddling I did find that changing line 4 to

vx = vy = vz = 0.9`30/Sqrt[3]; t1 = 0.;

produced plenty of digits in both print statements - but moving the backtick to after the 3 or the 0. did not have the same effect.

I naively thought that if I specified a certain precision in the calculation, Mma would work backwards and do everything necessary. How should I approach such issues?

Would somebody please enlighten me - or hit me with the stupid stick?

Update

I sitill don't have a clear rationale for this, so I am still hopeful of some insight, but I have discovered that if I were to type

Print[SetPrecision[
   Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];

then I would get

{-1.68585446084501100472152756993,{\[Theta]->6.28318530717958623199592693709,\[Phi]->0.785399718782704869823874105350}}

which is much closer to what I am trying to achieve. How do I do this for all calculations in a block or module - surely I don't have to specify this for each one?

(and why doesn't N[...., precision] achieve this result??)

Clearly I have misunderstood how to do this: I seem unable to understand how to get more digits out of a calculation and I can't see why - the following piece of code illustrates the issue.

Block[{γ, vx, vy, vz, t0, t1},
 t0 = γ (t1 - vx Sin[θ] Sin[ϕ] - 
     vy Cos[θ] Sin[ϕ] - vz Cos[ϕ]);
 vx = vy = vz = 0.9/Sqrt[3]; t1 = 0.;
 γ = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)];
 Print[Minimize[{t0, 
    0 <= θ < 2 Pi, -Pi <= ϕ < Pi}, {θ, ϕ}, 
   Reals]];
 Print[N[Minimize[{t0, 
     0 <= θ < 2 Pi, -Pi <= ϕ < Pi}, {θ, ϕ}, 
    Reals], 30]];
 ]

Results: both print statements give

{-1.68585,{θ->6.28319,ϕ->0.7854}}

Now by semi-random fiddling I did find that changing line 4 to

vx = vy = vz = 0.9`30/Sqrt[3]; t1 = 0.;

produced plenty of digits in both print statements - but moving the backtick to after the 3 or the 0. did not have the same effect.

I naively thought that if I specified a certain precision in the calculation, Mma would work backwards and do everything necessary. How should I approach such issues?

Would somebody please enlighten me - or hit me with the stupid stick?

Update

I sitill don't have a clear rationale for this, so I am still hopeful of some insight, but I have discovered that if I were to type

Print[SetPrecision[
   Minimize[{t0, 
     0 <= θ < 2 Pi, -Pi <= ϕ < Pi}, {θ, ϕ}, 
    Reals], 30]];

then I would get

{-1.68585446084501100472152756993,
   {θ->6.28318530717958623199592693709,ϕ->0.785399718782704869823874105350}}

which is much closer to what I am trying to achieve. How do I do this for all calculations in a block or module - surely I don't have to specify this for each one?

(and why doesn't N[...., precision] achieve this result??)

Found another ad hoc approach and updated to inform; still looking for understanding
Source Link
Julian Moore
  • 2.6k
  • 1
  • 12
  • 21

Clearly I have misunderstood how to do this: I seem unable to understand how to get more digits out of a calculation and I can't see why - the following piece of code illustrates the issue.

Block[{\[Gamma], vx, vy, vz, t0, t1},
 t0 = \[Gamma] (t1 - vx Sin[\[Theta]] Sin[\[Phi]] - 
     vy Cos[\[Theta]] Sin[\[Phi]] - vz Cos[\[Phi]]);
 vx = vy = vz = 0.9/Sqrt[3]; t1 = 0.;
 \[Gamma] = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)];
 Print[Minimize[{t0, 
    0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
   Reals]];
 Print[N[Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];
 ]

Results: both print statements give

{-1.68585,{[Theta]->6.28319,[Phi]->0.7854}}

{-1.68585,{\[Theta]->6.28319,\[Phi]->0.7854}}

Now by semi-random fiddling I did find that changing line 4 to

vx = vy = vz = 0.9`30/Sqrt[3]; t1 = 0.;

produced plenty of digits in both print statements - but moving the backtick to after the 3 or the 0. did not have the same effect.

I naively thought that if I specified a certain precision in the calculation, Mma would work backwards and do everything necessary. How should I approach such issues?

Would somebody please enlighten me - or hit me with the stupid stick?

Update

I sitill don't have a clear rationale for this, so I am still hopeful of some insight, but I have discovered that if I were to type

Print[SetPrecision[
   Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];

then I would get

{-1.68585446084501100472152756993,{\[Theta]->6.28318530717958623199592693709,\[Phi]->0.785399718782704869823874105350}}

which is much closer to what I am trying to achieve. How do I do this for all calculations in a block or module - surely I don't have to specify this for each one?

(and why doesn't N[...., precision] achieve this result??)

Clearly I have misunderstood how to do this: I seem unable to understand how to get more digits out of a calculation and I can't see why - the following piece of code illustrates the issue.

Block[{\[Gamma], vx, vy, vz, t0, t1},
 t0 = \[Gamma] (t1 - vx Sin[\[Theta]] Sin[\[Phi]] - 
     vy Cos[\[Theta]] Sin[\[Phi]] - vz Cos[\[Phi]]);
 vx = vy = vz = 0.9/Sqrt[3]; t1 = 0.;
 \[Gamma] = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)];
 Print[Minimize[{t0, 
    0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
   Reals]];
 Print[N[Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];
 ]

Results: both print statements give

{-1.68585,{[Theta]->6.28319,[Phi]->0.7854}}

Now by semi-random fiddling I did find that changing line 4 to

vx = vy = vz = 0.9`30/Sqrt[3]; t1 = 0.;

produced plenty of digits in both print statements - but moving the backtick to after the 3 or the 0. did not have the same effect.

I naively thought that if I specified a certain precision in the calculation, Mma would work backwards and do everything necessary. How should I approach such issues?

Would somebody please enlighten me - or hit me with the stupid stick?

Clearly I have misunderstood how to do this: I seem unable to understand how to get more digits out of a calculation and I can't see why - the following piece of code illustrates the issue.

Block[{\[Gamma], vx, vy, vz, t0, t1},
 t0 = \[Gamma] (t1 - vx Sin[\[Theta]] Sin[\[Phi]] - 
     vy Cos[\[Theta]] Sin[\[Phi]] - vz Cos[\[Phi]]);
 vx = vy = vz = 0.9/Sqrt[3]; t1 = 0.;
 \[Gamma] = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)];
 Print[Minimize[{t0, 
    0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
   Reals]];
 Print[N[Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];
 ]

Results: both print statements give

{-1.68585,{\[Theta]->6.28319,\[Phi]->0.7854}}

Now by semi-random fiddling I did find that changing line 4 to

vx = vy = vz = 0.9`30/Sqrt[3]; t1 = 0.;

produced plenty of digits in both print statements - but moving the backtick to after the 3 or the 0. did not have the same effect.

I naively thought that if I specified a certain precision in the calculation, Mma would work backwards and do everything necessary. How should I approach such issues?

Would somebody please enlighten me - or hit me with the stupid stick?

Update

I sitill don't have a clear rationale for this, so I am still hopeful of some insight, but I have discovered that if I were to type

Print[SetPrecision[
   Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];

then I would get

{-1.68585446084501100472152756993,{\[Theta]->6.28318530717958623199592693709,\[Phi]->0.785399718782704869823874105350}}

which is much closer to what I am trying to achieve. How do I do this for all calculations in a block or module - surely I don't have to specify this for each one?

(and why doesn't N[...., precision] achieve this result??)

Source Link
Julian Moore
  • 2.6k
  • 1
  • 12
  • 21

Increasing the precision of a calculation

Clearly I have misunderstood how to do this: I seem unable to understand how to get more digits out of a calculation and I can't see why - the following piece of code illustrates the issue.

Block[{\[Gamma], vx, vy, vz, t0, t1},
 t0 = \[Gamma] (t1 - vx Sin[\[Theta]] Sin[\[Phi]] - 
     vy Cos[\[Theta]] Sin[\[Phi]] - vz Cos[\[Phi]]);
 vx = vy = vz = 0.9/Sqrt[3]; t1 = 0.;
 \[Gamma] = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)];
 Print[Minimize[{t0, 
    0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
   Reals]];
 Print[N[Minimize[{t0, 
     0 <= \[Theta] < 2 Pi, -Pi <= \[Phi] < Pi}, {\[Theta], \[Phi]}, 
    Reals], 30]];
 ]

Results: both print statements give

{-1.68585,{[Theta]->6.28319,[Phi]->0.7854}}

Now by semi-random fiddling I did find that changing line 4 to

vx = vy = vz = 0.9`30/Sqrt[3]; t1 = 0.;

produced plenty of digits in both print statements - but moving the backtick to after the 3 or the 0. did not have the same effect.

I naively thought that if I specified a certain precision in the calculation, Mma would work backwards and do everything necessary. How should I approach such issues?

Would somebody please enlighten me - or hit me with the stupid stick?