Ask Your Question
0

sage integration differes from Mathematica

asked 2012-01-30 07:22:54 +0100

anonymous user

Anonymous

Hi, I'm trying to integrate

E(x) = ae^(-0.5(x/s)^2)cos(fx+phi)

Mathematica

A = Integrate[a Exp[-0.5 x^2/[Sigma]^2] Cos[f x + [Phi]], x]

gives me

0.626657 a E^(-0.5 f^2 [Sigma]^2) [Sigma] (Erf[(0.707107 x)/[Sigma]+(0.+0.707107 I) f [Sigma]] (Cos[[Phi]]-(0.+1. I) Sin[[Phi]])+Erfi[((0.+0.707107 I) x)/[Sigma]+0.707107 f [Sigma]] ((0.-1. I) Cos[[Phi]]+Sin[[Phi]]))

Doing

E = ae^(-0.5(x/s)^2)cos(fx+phi)

A = integrate(E, x)

Sages result is a different one (sorry, cannot copy output, but you can easily reproduce it yourself). The difference isn't obvious at first glance (at least not to me), but you can see it doing e.g.

A /. {a -> 100, f -> 1, [Sigma] -> 8, [Phi] -> 0, x -> 0}

gives 3.11179*10^-15 + 0. I

and Sage

show(A(a=100, f=1, s=8, phi=0, x=0).n())

results in 1.26977421759869e10-11+101.642197289814i

The result differs at least at zero. Anyone any idea what I'm doing wrong?

Cheers!

Ben

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-01-31 19:21:28 +0100

achrzesz gravatar image

Hi Ben

For special values of the constants there are no differences in the integral and the plot:

A=integrate(100exp(-1/2x^2/8^2)*cos(x),x,algorithm='mathematica_free');

L=[[l,numerical_integral(100exp(-1/2x^2/8^2)*cos(x),0,l)[0]] for l in srange(-6,6,0.1)];

list_plot(L,plotjoined=True)

edit flag offensive delete link more

Comments

Cheers man! So I've got to evaluate the stuff numerically before plotting. Usually I only do numpy and rarely sympy and recently had a look into sage again after some time. I start liking it ;) Thanks Ben

BenMoon gravatar imageBenMoon ( 2012-02-01 03:20:48 +0100 )edit
1

answered 2012-01-30 12:08:56 +0100

achrzesz gravatar image

The indefinite integral of a given function is only defined up to an additive constant

(and your results differ by a constant)

The definte integral, for example

sage: ii=integrate(100exp(-1/2x^2/8^2)*cos(x),x,0,+oo);

sage: ii

400sqrt(pi)sqrt(2)*e^(-32)

is the same in Mathematica (WolframAlpha)

edit flag offensive delete link more

Comments

Agree. Thanks haven't thought about the constant, which is of course right, however I'm not sure if that's actually the problem: Mathematica (for the above function): A(0) = 3.11179*10^-15 + 0. I A(1) = 83.9607 + 0. I A(20) = 3.15709 + 0. I Sage: A(0) = 1.26977421759869e-11+101.642197289814i A(1) = 83.9606807305601 A(20) = 3.15709049993006 To me that doesn't look like a constant... Furthermore I cannot plot the stuff ("plot(A(a=100, f=1, s=8, phi=0), (x, 10, 16))"), with this error: verbose 0 (4190: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 200 points. verbose 0 (4190: plot.py, generate_plot_points) Last error message: 'unable to simplify to float approximation' Thanks Ben

BenMoon gravatar imageBenMoon ( 2012-01-31 08:40:57 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-01-30 07:22:54 +0100

Seen: 745 times

Last updated: Jan 31 '12