Ask Your Question
1

taylor series of expression involving modulus of a complex expression

asked 2022-06-22 15:49:34 +0200

rhaynes74 gravatar image

updated 2022-06-22 17:05:45 +0200

slelievre gravatar image

Consider the following

sage: w = SR.var('w')
sage: a = -cos(w)^2 + 2*I*cos(w)*sin(w) + sin(w)^2 + 2.8*cos(w) - 2.8*I*sin(w) - 1.8

sage: b = abs(a)
sage: b.taylor(w, 0.1, 1)  # not the answer I expected!
-(0.8150178993589604 + 0.178042614591617*I)*w
+ 0.16258427059001673 + 0.0178042614591617*I

sage: c = sqrt(b.real()**2 + b.imag()**2)
sage: c.taylor(w, 0.1, 3)  # works as expected!
1.002855497443298*(w - 0.1)^3
+ 0.3184495453305423*(w - 0.1)^2
+ 0.8322931797904074*w
- 0.002146837324920048

So as you can see I have two mathematically equivalent expressions, b and c, but Sage is not able to directly find the Taylor series of the first.

Is there a way to convince Sage to do this correctly?

edit retag flag offensive close merge delete

Comments

I'm not sure that your question has a meaning (I'm not able to understand it). Consider :

sage: c.taylor(w, 0.1, 1)-b.taylor(w,0.1,1)
0.0
sage: c.taylor(w, 0.1, 3)-b.taylor(w,0.1,3)
0.0

What do you mean ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-06-22 18:47:16 +0200 )edit

Thanks for the response Emmanuel - now I am confused!! Another user came in and edited my question to make it look nicer but certainly I get a different result!

Here is my original source: w=SR.var('w') tt=abs(-cos(w)^2 + 2Icos(w)sin(w) + sin(w)^2 + 2.8cos(w) - 2.8Isin(w) - 1.8) print(tt.taylor(w,0.1,3)) print("") ttt=-cos(w)^2 + 2Icos(w)sin(w) + sin(w)^2 + 2.8cos(w) - 2.8Isin(w) - 1.8 lttt=sqrt(ttt.real()2+ttt.imag()2) print(lttt.taylor(w,0.1,3))

and output:

-(77.5983311918384 + 60.00589446569399I)(w - 0.1)^3 - (8.236463209769601 + 3.57404233017743I)(w - 0.1)^2 - (0.8150178993589604 + 0.178042614591617I)w + 0.16258427059001673 + 0.0178042614591617*I

1.002855497443298(w - 0.1)^3 + 0.3184495453305423(w ...(more)

rhaynes74 gravatar imagerhaynes74 ( 2022-06-22 19:04:13 +0200 )edit

Tip: indent code fragments by four spaces so they display properly.

slelievre gravatar imageslelievre ( 2022-06-22 19:38:47 +0200 )edit

Your "original code" didn't make it through this editor's markup. I guessed :

w=SR.var('w')
tt=abs(-cos(w)^2 + 2*I*cos(w)*sin(w) + sin(w)^2 + 2.8*cos(w) - 2.8*I*sin(w) - 1.8)
print(tt.taylor(w,0.1,3))
print("")
ttt=-cos(w)^2 + 2*I*cos(w)*sin(w) + sin(w)^2 + 2.8*cos(w) - 2.8*I*sin(w) - 1.8
lttt=sqrt(ttt.real()^2+ttt.imag()^2)
print(lttt.taylor(w,0.1,3))

Can you confirm ? If so, it turns out that

sage: bool(abs(ttt)==tt)
True

You seem to expect that ttt and ttt.abs() have the same Taylor development. It ain't necessarily so...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-06-22 23:07:28 +0200 )edit

Simple illustrative counter-example : see my answer

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-06-22 23:11:40 +0200 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2022-06-23 16:03:01 +0200

JTS gravatar image

updated 2022-06-23 16:03:18 +0200

You could expand around t=0 instead, for t = w + 0.1

var('t')
bmac = b.substitute(w=t-0.1).taylor(t,0,3)
cmac = c.substitute(w=t-0.1).taylor(t,0,3)
print(bmac)
print(cmac)

gives

(77.59833119183804 - 60.0058944656944I)t^3 - (8.236463209769589 - 3.574042330177453I)t^2 + (0.8150178993589599 - 0.1780426145916193I)t + 0.0810824806541207

(77.59833119183804 - 60.0058944656944I)t^3 - (8.236463209769589 - 3.574042330177453I)t^2 + (0.8150178993589599 - 0.1780426145916193I)t + 0.0810824806541207

edit flag offensive delete link more
0

answered 2022-06-22 23:17:50 +0200

Emmanuel Charpentier gravatar image

You seem to expect that f(x).taylor(x,0 3) is equal to f(x).abs().taylor(x,0,3).

There's nothing allowing such an expectation. Simple illustrative counter-example :

sage: with assuming(x, "real"):(cos(x)+I*sin(x)).exponentialize().simplify().taylor(x,0,5)
1/120*I*x^5 + 1/24*x^4 - 1/6*I*x^3 - 1/2*x^2 + I*x + 1
sage: with assuming(x, "real"):(cos(x)+I*sin(x)).abs().exponentialize().simplify().taylor(x,0,5)
1

HTH,

edit flag offensive delete link more

Comments

Of course not! I was comparing (or trying to compare) the Taylor series for abs(a(w)+I*b(w)) and sqrt(a(w)^2+b(w)^2) - at least at points where things are smooth.

rhaynes74 gravatar imagerhaynes74 ( 2022-06-22 23:49:16 +0200 )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

1 follower

Stats

Asked: 2022-06-22 15:49:34 +0200

Seen: 239 times

Last updated: Jun 23 '22