| New Reply |
Simplify in Mathematica |
Share Thread |
| Feb17-13, 07:35 AM | #1 |
|
Mentor
|
Simplify in Mathematica
Why do I keep getting output that looks like this when I use Mathematica?
$$\frac{2 b k |a+b v| (2 a+b v+b v \cos (t)) \sin ^2\left(\frac{t}{2}\right)}{(a+b v)^2 \sqrt{\left(\frac{1}{\sqrt{4 a^2 k^2 \sin ^4\left(\frac{t}{2}\right)+d^2 (a+b v)^2 \sin ^2(t)}}\right)^* \sqrt{4 a^2 k^2 \sin ^4\left(\frac{t}{2}\right)+d^2 (a+b v)^2 \sin ^2(t)}} \sqrt{4 a^2 k^2 \sin ^4\left(\frac{t}{2}\right)+d^2 (a+b v)^2 \sin ^2(t)}}$$ This is the output of a "Simplify" with the options Code:
{a, b, d, v, t} \[Element] Reals && k > 0
|
| Feb17-13, 01:13 PM | #2 |
|
|
No assumptions about domain and this is the result
In[1]:= Simplify[(2b k Abs[a+b v](2a+b v+b v Cos[t]) Sin[t/2]^2)/((a+b v)^2) Sqrt[(1/Sqrt[4a^2k^2 Sin[t/2]^4+d^2(a+b v)^2 Sin[t]^2])^2 Sqrt[4a^2k^2 Sin[t/2]^4+d^2(a+b v)^2 Sin[t]^2] Sqrt[4a^2k^2 Sin[t/2]^4+d^2(a+b v)^2 Sin[t]^2]]] Out[1]= (2*b*k*Abs[a + b*v]*(2*a + b*v + b*v*Cos[t])*Sin[t/2]^2)/(a + b*v)^2 So either I'm making a mistake when I have to type all your stuff back in just to give it to Mathematica or you have a problem in your desktop publishing, like that superscript "*" I see and I guessed that was supposed to be "2", or maybe there is a version difference. What is your actual raw code without any desktop publishing? |
| Feb17-13, 03:46 PM | #3 |
|
Mentor
|
I should have included the full code in my post. Sorry about that. You can see it below. I should perhaps also mention that this is my first attempt to use Mathematica to do anything at all really. So it's possible that I'm doing many things wrong. I've been doing this on someone else's copy of Mathematica 7. I don't have access to the latest version at the moment.
The * superscript comes out as ^\[Conjugate] when I do a "copy as plain text". Code:
X={{a,b,0 ,0},{-v d,d,0,0},{0,0,k,0},{0,0,0,k}}
F={{1,0,0,0},{0,Cos[t],-Sin[t],0},{0,Sin[t],Cos[t],0},{0,0,0,1}}
Y=Simplify[Inverse[X].F.X]
p=Take[Y,{2,4},{1,1}]
q=Take[Y,{1,1},{2,4}]
B=Take[Y,{2,4},{2,4}]
Simplify[Norm[p],{a,b,d,v,t}\[Element]Reals && k>0];
temp1=Simplify[{{1,0,0}}.p/Norm[p],{a,b,d,v,t}\[Element]Reals && k>0];
temp2=Simplify[{{0,1,0}}.p/Norm[p],{a,b,d,v,t}\[Element]Reals && k>0];
T=(Abs[v]/v)temp1[[1,1]];
S=(Abs[v]/v) temp2[[1,1]];
R1={{T,S,0},{-S,T,0},{0,0,1}}
R1p=Simplify[R1.p]
R1p1=R1p[[1,1]]
R1B=Simplify[R1.B,{a,b,d,v,t}\[Element]Reals && k > 0]
x=Take[R1B,{2,2},{1,3}];
z={{x[[1,2]],-x[[1,1]],0}};
zz=Simplify[z/Norm[z],{a,b,d,v,t}\[Element]Reals && k>0];
R2={{zz[[1,1]],-zz[[1,2]],0},{zz[[1,2]],zz[[1,1]],0},{0,0,1}}
J=Simplify[R1.B.R2,{a,b,d,v,t}\[Element]Reals && k>0]
Simplify[J,a k^2==d^2(a+b v)]
qR2=Simplify[q.R2,{a,b,d,v,t}\[Element]Reals && k>0]
Simplify[qR2,a k^2==d^2(a+b v)]
w=-R1p[[1,1]]/J[[1,1]]
|
| Feb17-13, 09:39 PM | #4 |
|
|
Simplify in Mathematica
The first thing I would look at is
Norm[p] because it appears that so much of your code depends on that. Is Norm[p] supposed to be something that you are not seeing in your notebook? |
| Feb17-13, 10:09 PM | #5 |
|
Mentor
|
p is the 3×1 matrix
$$\begin{pmatrix} \frac{2 a v \sin ^2\left(\frac{t}{2}\right)}{a+b v} \\ -\frac{d v \sin (t)}{k} \\ 0 \end{pmatrix}$$ and Norm[p] is the norm of p, i.e. ##\|p\|=\sqrt{(p_1)^2+(p_2)^2+(p_3)^2}##. If I just evaluate Norm[p], I get $$\sqrt{\frac{4 a v \sin ^2\left(\frac{t}{2}\right) (a v)^* \sin ^2\left(\frac{t^*}{2}\right)}{(a+b v) (a+b v)^*}+\frac{d v \sin (t) (d v \sin (t))^*}{k k^*}}$$ If I evaluate Simplify[Norm[p],{a,b,d,v,t}\[Element]Reals && k>0], I get $$\frac{|v| \sqrt{4 a^2 k^2 \sin ^4\left(\frac{t}{2}\right)+d^2 \sin ^2(t) (a+b v)^2}}{k |a+b v|}$$ So I would say that "Simplify" is doing OK so far. |
| Feb18-13, 12:01 AM | #6 |
|
|
I'm not finding an explanation.
Perhaps someone else can spot something. Something that might relate, many programming languages make a big distinction between row vectors and column vectors. Mathematica doesn't, a vector will be interpreted as row or column as needed. This means you don't need to go to the trouble to try to construct column vectors. In fact in some old versions of Mathematica adding an extra layer of {} to try to force elements to be in a column could cause problems, but they may have found and fixed those by now. I do see that you have column vectors with the extra layer of {} at places in your code. Hopefully someone else can spot something that I just seem to be blind to at the moment. If you could show specific examples of where the calculations seem to be incorrect that might help someone, something more specific than "But something is already wrong with R1p." |
| Feb18-13, 12:14 AM | #7 |
|
Mentor
|
That's OK. Thanks for trying. I did say what the problem with R1p is. The first component is of the form
$$\frac{|a+bv|X}{(a+bv)^2 Y}.$$ Since all the variables are real, this can be simplified to $$\frac{X}{|a+bv|Y},$$ but Mathematica doesn't do that, even when I explicitly tell it that all variables are real by changing the definition to Code:
R1p=Simplify[R1.p,{a,b,d,v,t}\[Element]Reals && k>0]
Edit 2: I think the problem with the example in the OP is that Mathematica is concerned that the things under the square roots are zero or negative. |
| Feb19-13, 09:40 AM | #8 |
|
Mentor
|
I could still use some help from someone who understands the Simplify feature better than I do. One of the expressions that show up in the calculation can also be generated by the following code.
Code:
z=(d v (a+b v) Sin[t])/(Abs[v] Sqrt[Conjugate[1/Sqrt[4 a^2 k^2 Sin[t/2]^4+d^2 (a+b v)^2 Sin[t]^2]] Sqrt[4 a^2 k^2 Sin[t/2]^4+d^2 (a+b v)^2 Sin[t]^4]] Sqrt[4 a^2 k^2 Sin[t/2]+d^2 (a+b v)^2 Sin[t]]) $$\frac{d v \sin(t) (a+b v)}{|v| \sqrt{4 a^2 k^2 \sin \left(\frac{t}{2}\right) +d^2 \sin(t) (a+b v)^2} \sqrt{\sqrt{4 a^2 k^2 \sin^4\left(\frac{t}{2}\right) +d^2 \sin^4(t) (a+b v)^2} \left(\frac{1}{\sqrt{4 a^2 k^2 \sin^4\left(\frac{t}{2}\right) +d^2 (a+b v)^2 \sin ^2(t)}}\right)^*}}$$ The following Simplify does absolutely nothing. Code:
Simplify[z,{a,b,d,v,k,t}\[Element]Reals && 4 a^2 k^2 Sin[t/2]^4+d^2 (a+b v)^2 Sin[t]^2>0 && k>0]
Here's a simpler thing that Mathematica fails to simplify. Code:
Simplify[v^2/Abs[v], v\[Element]Reals && v!=0] |
| Feb19-13, 03:59 PM | #9 |
|
Mentor
|
Try using FullSimplify instead of Simplify.
FullSimplify[v^2/Abs[v], v \[Element] Reals && v != 0] gives Abs[v] FullSimplify is a lot slower than Simplify (even when it achieves the same end result) because it uses a lot more transformation rules. |
| Feb19-13, 07:11 PM | #10 |
|
Mentor
|
To produce the LaTeX you see, I ran the code from the code box and then did a copy as LaTeX. My latest version of the code (I did everything over from scratch) doesn't produce an output with "dv" in the numerator anywhere, but I get a similar expression in which all three of the "small" square roots are the same. They are identical to the one that's being complex conjugated in the incorrect LaTeX above. I will try to describe the problem again, since my description contains several mistakes. Consider this code. Code:
M={{a,b,0,0},{-v d,d,0,0},{0,0,k,0},{0,0,0,k}}
F={{1,0,0,0},{0,Cos[t],-Sin[t],0},{0,Sin[t],Cos[t],0},{0,0,0,1}}
X=Simplify[Inverse[M].F.M]
p=Take[X,{2,4},{1,1}]
q=Take[X,{1,1},{2,4}]
S=Take[X,{2,4},{2,4}]
r=X[[1,1]]
pn=Simplify[p/Norm[p],{a,b,d,v,k,t}\[Element]Reals]
R=Simplify[{{pn[[1,1]],pn[[2,1]],0},{-pn[[2,1]],pn[[1,1]],0},{0,0,1}},a+b v>0]
RS = Simplify[R.S, k > 0]
y=Take[RS,{2,2},{1,3}]
yn=Simplify[y/Norm[y],{a,b,d,v,k,t}\[Element]Reals && k>0]
yn[[1,1]]
$$\frac{d v \sin (t) (a+b v)}{|v| \sqrt{4 a^2 k^2 \sin ^4\left(\frac{t}{2}\right)+d^2 \sin ^2(t) (a+b v)^2} \sqrt{\sqrt{4 a^2 k^2 \sin ^4\left(\frac{t}{2}\right)+d^2 \sin ^2(t) (a+b v)^2} \left(\frac{1}{\sqrt{4 a^2 k^2 \sin ^4\left(\frac{t}{2}\right)+d^2 (a+b v)^2 \sin ^2(t)}}\right)^*}}$$ This should be accurate, since the only thing I changed manually was the complex conjugation symbol. |
| Feb20-13, 08:45 AM | #11 |
|
Mentor
|
Code:
yn=FullSimplify[y/Norm[y],{a,b,d,v,k,t}\[Element]Reals && k>0]
Now, if you know that the term under the square root is not just real, but positive, then it can simplify further, but putting in a condition like: Code:
4 a^2 k^2 Sin[t/2]^4 + d^2 (a + b v)^2 Sin[t]^2 > 0 What you can do in situations like that is make a direct substitution rather than a simplifying assumption: Code:
yn = FullSimplify[y/Norm[y], {a, b, d, v, k, t} \[Element] Reals && k > 0]
/. {Sign[4 a^2 k^2 Sin[t/2]^4 + d^2 (a + b v)^2 Sin[t]^2] -> 1}
|
| Feb20-13, 11:35 AM | #12 |
|
Mentor
|
Wow. FullSimplify really worked much better on this expression. Thanks for the tip. That substitution thing is interesting too.
|
| Feb20-13, 01:38 PM | #13 |
|
Recognitions:
|
Code:
Sign[4 a^2 k^2 Sin[t/2]^4 + d^2 (a + b v)^2 Sin[t]^2] -> 1 It's usually better to solve for one variable in the substitution you want to make, and write something of the form Code:
var -> (some long expression) |
| New Reply |
Similar discussions for: Simplify in Mathematica
|
||||
| Thread | Forum | Replies | ||
| MATHEMATICA : Forcing Logarithms to Simplify | Math & Science Software | 3 | ||
| Simplify this expression with Mathematica | Math & Science Software | 4 | ||
| Help urgently needed in Mathematica Simplify | Math & Science Software | 1 | ||
| Mathematica can't simplify | Math & Science Software | 4 | ||
| How to simplify an expression in Mathematica | Math & Science Software | 15 | ||