Student Support Forum: 'factor inside root' topicStudent Support Forum > General > Archives > "factor inside root"

 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic
 Author Comment/Response Bill Simpson 01/30/13 3:46pm The usual method of doing something like this is to use patterns and a replacement rule, like this: In[1]:= a*Sqrt[b]/.u_*Sqrt[v_]->Sqrt[u^2*(v)] Out[1]= Sqrt[a^2*b] That looks for something times square root of something else and replaces it with square root of something squared times something else Now we try it with your example In[2]:= 1.01792*10^-40 Sqrt[(2.6336*10^72+4.80538*10^77 kx^2+8.76809*10^82 kx^4+4.80538*10^77 ky^2+3.65593*10^83 kx^2 ky^2+8.76809*10^82 ky^4-9.61076*10^77 kz^2+3.65593*10^83 kx^2 kz^2+3.65593*10^83 ky^2 kz^2+8.76809*10^82 kz^4)]/.u_*Sqrt[v_]->Sqrt[u^2*(v)] Out[2]= 1.01792*10^-40 Sqrt[(2.6336*10^72+4.80538*10^77 kx^2+8.76809*10^82 kx^4+4.80538*10^77 ky^2+3.65593*10^83 kx^2 ky^2+8.76809*10^82 ky^4-9.61076*10^77 kz^2+3.65593*10^83 kx^2 kz^2+3.65593*10^83 ky^2 kz^2+8.76809*10^82 kz^4)] Was there an error? We got back exactly the original. That would happen if the pattern didn't match. But it also can happen when Mathematica thinks it should rearrange an expression they way it wants to. Try a slight variation of that rule with a Hold that tries to block Mathematica from doing some rearrangement. In[3]:= 1.01792*10^-40 Sqrt[(2.6336*10^72+4.80538*10^77 kx^2+8.76809*10^82 kx^4+4.80538*10^77 ky^2+3.65593*10^83 kx^2 ky^2+8.76809*10^82 ky^4-9.61076*10^77 kz^2+3.65593*10^83 kx^2 kz^2+3.65593*10^83 ky^2 kz^2+8.76809*10^82 kz^4)]/.u_*Sqrt[v_]->Hold[Sqrt[u^2*(v)]] Out[3]= Hold[Sqrt[1.01792*^-40^2*(2.6336*10^72+4.80538*10^77 kx^2+8.76809*10^82 kx^4+4.80538*10^77 ky^2+3.65593*10^83 kx^2 ky^2+8.76809*10^82 ky^4-9.61076*10^77 kz^2+3.65593*10^83 kx^2 kz^2+3.65593*10^83 ky^2 kz^2+8.76809*10^82 kz^4)]] That shows it did the replacement. But there is still that Hold and you can't use that result until you ReleaseHold to get a normal expression. So In[4]:= ReleaseHold[%] Out[4]= 1.01792*10^-40 Sqrt[(2.6336*10^72+4.80538*10^77 kx^2+8.76809*10^82 kx^4+4.80538*10^77 ky^2+3.65593*10^83 kx^2 ky^2+8.76809*10^82 ky^4-9.61076*10^77 kz^2+3.65593*10^83 kx^2 kz^2+3.65593*10^83 ky^2 kz^2+8.76809*10^82 kz^4)] And Mathematica again thinks it knows what should be done and factors your constant out of the Sqrt. Usually, when you are trying to get Mathematica to do something that it really doesn't want to do, you will find it difficult. Please check this carefully to make certain I have not made any errors. URL: ,

 Subject (listing for 'factor inside root') Author Date Posted factor inside root Simone 01/30/13 09:16am Re: factor inside root Bill Simpson 01/30/13 3:46pm Re: factor inside root yehuda 01/31/13 08:58am
 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic