Re: RE: complex analysis problem in mathematica 3.0
- To: mathgroup at smc.vnet.net
- Subject: [mg48493] Re: [mg48476] RE: [mg48459] complex analysis problem in mathematica 3.0
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 2 Jun 2004 04:21:58 -0400 (EDT)
- References: <NDBBJGNHKLMPLILOIPPOCEBMEBAA.djmp@earthlink.net>
- Sender: owner-wri-mathgroup at wolfram.com
Of course "by quicker" I meant : requiring less typing ;-) I do not doubt that MapLevelParts can be very useful, although as a general principle I prefer to consider each such problem individually and try to find the most suitable approach rather than rely on a universal function. My main reason is that doing so is a good practice in Mathematica programming. Andrzej On 1 Jun 2004, at 23:03, David Park wrote: > I suspected I would get some alternative methods to simplify, but I > don't > think that they are all that obvious, and therefore not quicker. I > still > think a MapLevelParts command would be useful. It complements MapAt and > gives much better direct control at manipulating expressions. > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > > From: Andrzej Kozlowski [mailto:akoz at mimuw.edu.pl] To: mathgroup at smc.vnet.net > > A quicker way to get the same answer is: > > step1 = 1/(s^3 + 2*s^2 + 2*s + 1) /. s -> I*w > > Collect[ComplexExpand[step1] /. I -> i, i, > Simplify] /. i -> I > > > (1 - 2*w^2)/(w^6 + 1) + (I*w*(w^2 - 2))/(w^6 + 1) > > P.S. Although it is true one can't use j, one can use the character > entered as escape j j escape, which looks like a fancy j. > > > Andrzej Kozlowski > Chiba, Japan > http://www.mimuw.edu.pl/~akoz/ > > > > > On 1 Jun 2004, at 16:02, David Park wrote: > >> You can't use j. Use the Mathematica I. >> >> step1 = 1/(s^3 + 2*s^2 + 2*s + 1) /. s -> I*w >> >> Then you can separate into real and imaginary parts by using >> ComplexExpand. >> >> step2 = ComplexExpand[step1] >> 1/((1 - 2*w^2)^2 + (2*w - w^3)^2) - >> (2*w^2)/((1 - 2*w^2)^2 + (2*w - w^3)^2) + >> I*(-((2*w)/((1 - 2*w^2)^2 + (2*w - w^3)^2)) + >> w^3/((1 - 2*w^2)^2 + (2*w - w^3)^2)) >> >> But how do we further simplify that? We can't use Simplify or Together >> on >> the entire expression because that mixes the real and imaginary parts >> together again. We can get a partial simplification by mapping >> Simplify onto >> the parts. >> >> step3 = Simplify /@ step2 >> 1/(1 + w^6) - (2*w^2)/(1 + w^6) + (I*w*(-2 + w^2))/ >> (1 + w^6) >> >> But the expression could be further simplified by using Together on >> the >> first two terms. Unfortunately Mathematica doesn't provide any direct >> method >> of doing that other than resorting to a rule that duplicates the parts >> on >> the lhs. I think that Mathematica needs an additional routine that >> would >> complement MapAt. I call it MapLevelParts and it maps a function to a >> subset >> of level parts in an expression. The common application would be to a >> subset >> of terms in a Plus expression or a subset of factors in a Times >> expression. >> >> MapLevelParts::usage = >> "MapLevelParts[function, {topposition, levelpositions}][expr] will >> map \ >> the function onto the selected level positions in an expression. \ >> Levelpositions is a list of the selected parts. The function is >> applied to \ >> them as a group and they are replaced with a single new expression. >> Other \ >> parts not specified in levelpositions are left unchanged.\nExample:\na >> + b + >> \ >> c + d + e // MapLevelParts[f, {{2,4,5}}] -> a + c + f[b + d + e]"; >> >> MapLevelParts[func_, >> part : {toppart___Integer?Positive, >> subp : {_Integer?Positive, >> eprest__Integer?Positive}}][expr_] := >> Module[{work, subparts, npos, null, i, nnull = Length[{eprest}]}, >> work = func@Part[expr, Sequence @@ part]; >> subparts = Thread[{toppart, subp}]; >> newparts = {work, Table[null[i], {i, 1, nnull}]} // Flatten; >> npos = Partition[Range[nnull + 1], 1]; >> ReplacePart[expr, newparts, subparts, npos] /. null[_] -> >> Sequence[] >> ] >> >> Now we can use Together on just the first two terms of the sum. >> >> step3 // MapLevelParts[Together, {{1, 2}}] >> (1 - 2*w^2)/(1 + w^6) + (I*w*(-2 + w^2))/(1 + w^6) >> >> David Park >> > > >