How should I use the numerical method .n()?

asked 2024-04-25 20:38:04 +0100

Morgan gravatar image

updated 2024-04-29 15:22:28 +0100

dan_fulea gravatar image

If I want to numerically calculate an expression involving several terms and I am worried about efficiency should I numerically calculate each term? For example is there a difference between:

data = [ (sin(t)*exp(t)).n() for t in srange(0, 10, 0.01) ]

vs

data = [ sin(t).n()*exp(t).n() for t in srange(0, 10, 0.01) ]

?

edit retag flag offensive close merge delete

Comments

1

In response to the specific question at the end: [(sin(t)*exp(t)).n() for t in srange(0,10,0.01)] == [sin(t).n()*exp(t).n() for t in srange(0,10,0.01)] returns True.

John Palmieri gravatar imageJohn Palmieri ( 2024-04-26 00:12:35 +0100 )edit
1

This should not matter unless you expect some kind of precision loss (e.g., adding entities of significantly different magnitude).

Max Alekseyev gravatar imageMax Alekseyev ( 2024-04-26 05:07:17 +0100 )edit