From: Bill Rowe on 3 Aug 2010 06:41 On 8/2/10 at 7:04 AM, blamm64(a)charter.net (blamm64) wrote: >Given the expression: >eff = (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b])) >After this I enter >eff /. {dm*Pi -> L/Tan[a]} >and get a result that does not, for a reason I cannot fathom and >believe to be a bug, replace one instance of dm*Pi. The result of >the evaluation yields >L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a])) >Precisely the same result occurs with eff //.{dm*Pi->L/Tan[a]} >Why is the one remaining dm*Pi not replaced with L/Tan[a]? Replacements are done using a very literal matching on the =46ullForm of the expression. There is no algebra done until after the replacement occurs. In this specific instance In[11]:= FullForm[eff] Out[11]//FullForm= Times[Power[dm,-1],L,Power[Pi,-1],Power[Plus[Times[dm,mu,Pi],Times[L,Cos[b]]],-1],Plus[Times[-1,L,mu],Times[dm,Pi,Cos[b]]]] Note, the dm and Pi found in the denominator internally are seen by Mathematica as being Power[dm,-1] and Power[Pi, -1]. Additionally, In[15]:= MatchQ[Times[Power[dm, -1], Power[Pi, -1]], dm Pi] Out[15]= False This lack of matching is why the one dm*Pi you see in the denominator did not get replaced. This is the way ReplaceAll (/.) and ReplaceRepeated (//.) are supposed to work. You can get the result you want by doing: In[16]:= eff /. {dm -> L/Tan[a]/Pi} Out[16]= (Tan[a]*(L*Cot[a]*Cos[b] - L*mu))/ (L*mu*Cot[a] + L*Cos[b]) or In[18]:= eff //. {dm*Pi -> L/Tan[a], 1/dm 1/Pi -> Tan[a]/L} Out[18]= (Tan[a]*(L*Cot[a]*Cos[b] - L*mu))/ (L*mu*Cot[a] + L*Cos[b]) The key to understanding why any replacement doesn't work as expected is to look at the FullForm of the expression containing the things to be replaced. >By the way, how do you guys copy input or output from Mathematica >notebook into this usergroup window? I had to do all this by hand, >copy it from here into a notebook, and execute the notebook cells just >to make sure I was getting it correct. I ran across this originally >when I was constructing a simple notebook for doing some Acme power >screw calculations. Select the cell you want to copy then change it to InputForm. See the menu item Cell->Convert To->input Form. Note, this should have a keyboard short cut which on a Mac is cmd-shift-i. Once you have converted the cell to input form, you will be able to copy and paste that directly into an email without the manual typing. Also note while it is possible to create something readable with subscripts, Greek symbols etc in InputForm, posts are generally much more readable if you avoid using those things.
From: David Park on 3 Aug 2010 06:42 Matching expressions in denominators is always a small problem for beginners because the intuitive pattern does not appear in the underlying expression. eff1 = (L*(-L*mu + L*Cos[b]*Cot[b]))/(dm*Pi*(L*Cos[b] + L*mu*Cot[a])); Look at the FullForm expressions: eff1//FullForm dm*Pi -> L/Tan[a] // FullForm The correct rule is: 1/(dm*Pi) -> 1/(L/Tan[a]) // FullForm eff1 /. {1/(dm*Pi) -> 1/(L/Tan[a])} Concerning posting code: I usually select and copy the expression within a cell using the right click context menu CopyAs/InputText and then paste that into the posting. I prefer not to have In-Out numbers because they make it difficult to copy from a posting back into a notebook (or else I don't know how to do it.) The only problem I have is when I have a series of statements within one cell with line returns between statements. Sometimes the line returns get removed in the posting and I'm not sure how to stop that, other than inserting extra blank lines. David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: blamm64 [mailto:blamm64(a)charter.net] Given the expression: eff = (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b])) After this I enter eff /. {dm*Pi -> L/Tan[a]} and get a result that does not, for a reason I cannot fathom and believe to be a bug, replace one instance of dm*Pi. The result of the evaluation yields L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a])) Precisely the same result occurs with eff //.{dm*Pi->L/Tan[a]} Why is the one remaining dm*Pi not replaced with L/Tan[a]? In fact, when define manually define eff1 as eff1 = (L*(-L*mu + L*Cos[b]*Cot[b]))/(dm*Pi*(L*Cos[b]+L*mu*Cot[a])) which is as you can see the result of the first ReplaceAll execution, and then enter eff1 /. {dm*Pi->L/Tan[a]} Mathematica returns eff1 unaltered! Now, I say this is a bug, so of course I'm probably missing something and it isn't a bug. I have to jump through syntactic hoops to get the 'right' answer: FullSimplify[eff /.{dm*Pi->L/Tan[a]}]/.{dm*Pi->L/Tan[a]}//FullSimplify and FullSimplify[eff /. {dm*Pi->L/Tan[a]} does no good either. It is not at all obvious to me what I might be missing with such an apparently simple replacement. By the way, how do you guys copy input or output from Mathematica notebook into this usergroup window? I had to do all this by hand, copy it from here into a notebook, and execute the notebook cells just to make sure I was getting it correct. I ran across this originally when I was constructing a simple notebook for doing some Acme power screw calculations. -Brian Lamm (Windows XP x64 Version 2003 SP2, Mathematica 7.0.1)
From: Peter Breitfeld on 3 Aug 2010 06:57 If you look at the FullForm of eff1 you get FullForm[eff1] Times[Power[dm,-1],L,Power[Pi,-1],Power[Plus[Times[L,Cos[b]], Times[L,mu,Cot[a]]],-1],Plus[Times[-1,L,mu],Times[L,Cos[b],Cot[a]]]] As you can see, the FullForm contains nowhere dm*Pi, (FullForm is Times[dm,Pi]), so this pattern will never match and can't be replaced. Generally, it's better to replace Symbols instead of expressions, because the FullForm of an expression mostly looks quite different from what you expect and Patterns were always matched against the FullForm. So this will work: eff/.dm->L/(Pi*Tan[a]) Out=((-L mu + L Cos[b] Cot[a]) Tan[a])/(L Cos[b] + L mu Cot[a]) //Peter blamm64 wrote: > Given the expression: > > eff = (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b])) > > After this I enter > > eff /. {dm*Pi -> L/Tan[a]} > > and get a result that does not, for a reason I cannot fathom and > believe to be a bug, replace one instance of dm*Pi. The result of the > evaluation yields > > L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a])) > > Precisely the same result occurs with eff //.{dm*Pi->L/Tan[a]} > > Why is the one remaining dm*Pi not replaced with L/Tan[a]? > > In fact, when define manually define eff1 as > > eff1 = (L*(-L*mu + L*Cos[b]*Cot[b]))/(dm*Pi*(L*Cos[b]+L*mu*Cot[a])) > > which is as you can see the result of the first ReplaceAll execution, > and then enter > > eff1 /. {dm*Pi->L/Tan[a]} > > Mathematica returns eff1 unaltered! > > Now, I say this is a bug, so of course I'm probably missing something > and it isn't a bug. I have to jump through syntactic hoops to get the > 'right' answer: > > FullSimplify[eff /.{dm*Pi->L/Tan[a]}]/.{dm*Pi->L/Tan[a]}//FullSimplify > > and FullSimplify[eff /. {dm*Pi->L/Tan[a]} does no good either. > > It is not at all obvious to me what I might be missing with such an > apparently simple replacement. > > By the way, how do you guys copy input or output from Mathematica > notebook into this usergroup window? I had to do all this by hand, > copy it from here into a notebook, and execute the notebook cells just > to make sure I was getting it correct. I ran across this originally > when I was constructing a simple notebook for doing some Acme power > screw calculations. > > -Brian Lamm > (Windows XP x64 Version 2003 SP2, Mathematica 7.0.1) > -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
First
|
Prev
|
Pages: 1 2 Prev: A distribution problem using Mathematica Next: Exporting into PowerPoint |