0
$\begingroup$

I have a matrix of the form:
$$\left( \begin{array}{ccc} 1 & \frac{\delta I_1(\kappa )}{I_0(\kappa )} & 0 \\ \frac{I_1(\kappa ) \delta ^*}{I_0(\kappa )} & \frac{\delta (I_1(\kappa )+\kappa I_2(\kappa )) \delta ^*}{\kappa I_0(\kappa )} & 0 \\ 0 & 0 & \frac{\delta I_1(\kappa ) \delta ^*}{\kappa I_0(\kappa )} \\ \end{array} \right)$$
That I want to convert to the form:
$$\begin{pmatrix}1&g_c\delta&0\\g_c\delta^*&\frac{(1+g)}{2}|\delta|^2&0\\0&0&\frac{(1-g)}{2}|\delta|^2\end{pmatrix}$$
where $g_c=\frac{I_1(\kappa)}{I_0(\kappa)}$ and $g=\frac{I_2(\kappa)}{I_0(\kappa)}$
For the time being I don't speak about converting $\delta\delta^*$ to $|\delta|^2$. I've asked that question here
But about the other parts, I've used the following code:

Tvol[[1, 2]] /. {BesselI[1, κ]/BesselI[0, κ] -> Subscript[g, c]} // Simplify // TraditionalForm

$$\delta g_c$$

Tvol[[2, 1]] /. {BesselI[1, κ]/BesselI[0, κ] -> Subscript[g, c]} // Simplify // TraditionalForm  

$$g_c \delta ^*$$

Tvol[[2, 2]] /. {BesselI[1, κ] -> κ/2 (BesselI[0, κ] - BesselI[2, κ])} // FullSimplify // TraditionalForm  

$$\frac{\delta \delta ^* (I_0(\kappa )+I_2(\kappa ))}{2 I_0(\kappa )}$$

Tvol[[2, 2]] /. {BesselI[2, κ] -> g*BesselI[0, κ]} //FullSimplify // TraditionalForm  

$$\delta \delta ^* \left(g+\frac{I_1(\kappa )}{\kappa I_0(\kappa )}\right)$$
I wonder why at this step mathematica doesn't simply replace $\frac{I_0(\kappa)}{I_0(\kappa)}=1$ and $\frac{I_2(\kappa)}{I_0(\kappa)}=g$ to reach to the simple form:
$$\delta \delta ^*\frac{ 1+g}{2}$$
and returns back to $I_1(\kappa)$ ?
I have changed the code several times but none of them helped!!!

$\endgroup$

closed as off-topic by march, MarcoB, yohbs, Silvia, Dr. belisarius Sep 20 '15 at 5:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – yohbs, Silvia
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ It worked when I tried it. $\endgroup$ – march Sep 18 '15 at 0:51
  • $\begingroup$ Perhaps I don't understand the question,but BesselI[0, k]/BesselI[0, k]returns 1 $\endgroup$ – Dr. belisarius Sep 18 '15 at 0:55
  • 2
    $\begingroup$ possible duplicate of What are the most common pitfalls awaiting new users? $\endgroup$ – march Sep 18 '15 at 3:19
  • $\begingroup$ I seem to have yesterday answered this question here: mathematica.stackexchange.com/questions/94820/… $\endgroup$ – Alexei Boulbitch Sep 18 '15 at 7:32
  • $\begingroup$ @AlexeiBoulbitch yes you did. But as you might remember I said I should reach to the other form from the identity $I_1(\kappa)=\frac{\kappa}{2}(I_0(\kappa)-I_2(\kappa))$ and you said do as what I have done. Trying to do that I encountered the error. Anyway I'm going to have a comprehensive look on mathematica's syntax before trying any thing. Seems that mathematica isn't easy enough to learn it just through trial and error. $\endgroup$ – Sepideh Abadpour Sep 18 '15 at 7:52
4
$\begingroup$

I'm voting to close this question, but I think you could use a little guidance here nonetheless, so I am posting this as CW. It is important that you learn the basic ins-and-outs of MMA. I'm sure you've been directed there before, but make sure you carefully peruse What are the most common pitfalls awaiting new users?

I feel like maybe, in this case, the particular problem is that you are Assuming commands will have side effects which they don't:

The /. command (otherwise known as ReplaceAll) does not have the side effect of writing over the original expression. For instance, evaluate

Clear[a, b]
a = b;
a /. b -> 1
a

and carefully try to understand the results.

In your case, you need to either update Tvol at each stop, or do both replacements at once, and what you choose to do depends on what you need to do later. Either:

Tvol[[2, 2]] = Tvol[[2, 2]] /. {BesselI[1, κ] -> κ/2 (BesselI[0, κ] - BesselI[2, κ])} // FullSimplify
Tvol[[2, 2]] = Tvol[[2, 2]] /. {BesselI[2, κ] -> g*BesselI[0, κ]} //FullSimplify

or

Tvol[[2, 2]] //. {BesselI[2, κ] -> g*BesselI[0, κ], BesselI[1, κ] -> κ/2 (BesselI[0, κ] - BesselI[2, κ])} // FullSimplify

will result in the expression that you want. The first will change the the value of Tvol, while the second will not.

$\endgroup$
  • 1
    $\begingroup$ OMG. Mathemtica is hard to learn, isn't it? :) Never occurred to me that the OP may have thought that $\endgroup$ – Dr. belisarius Sep 18 '15 at 3:50
  • $\begingroup$ @belisarius It's really hard to learn. consider here I never had such experience in C++ or MATLAB. The same code that has done the trick in the same file, doesn't work afew lines later and it really drives you crazy. There are a lot of alternative ways to writ the same code and you don't know which will work properly this time! I don't know but it does not seem very regular. You cannot use the same rule multiple times! Or maybe I'm wrong? Please correct me if I think in the wrong way?! $\endgroup$ – Sepideh Abadpour Sep 18 '15 at 4:15
  • $\begingroup$ Ok, seems that I should write everything that I've learned here in these 3 days in a seperate non-digital notebook. Including the questions I've favorited and Learn them before proceeding :) $\endgroup$ – Sepideh Abadpour Sep 18 '15 at 4:21
  • $\begingroup$ @sepideh As I wrote here, and many times before: . "Mathematica is a wild beast and you need to take your time for taming it " $\endgroup$ – Dr. belisarius Sep 18 '15 at 4:21
  • $\begingroup$ @march you mean /. doesn't have side effects but //. does have? I'll take your advice and will peruse that question. But in general is there a command that you can write at the head of other commands at each step to explicitly say that you want to store the new values in variables? I think I need this feature in my notebook from the begining to the end!! $\endgroup$ – Sepideh Abadpour Sep 18 '15 at 11:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.