0
$\begingroup$

Here is my code. I have an equation that is given below. This code sorts through the terms and puts each term into a list and then each factor of the term into another list. I am able to call each factor in the equation.

eqn = Derivative[1][f1][y] . E^(I*x)*Derivative[1][f2][y] . 
     (2*I*E^(2*I*x)) + Derivative[1][f1][y] . 
     (I*E^(I*x))*Derivative[1][f2][y] . E^(2*I*x) + 
 Derivative[1][f3][y] . (3*I*E^(3*I*x)) + 
 Derivative[1][g3][y] . (I*E^(I*x)) + 
 (-f2[y]) . (2*I*E^(2*I*x))*Derivative[2][f1][y] . 
     E^(I*x) + (-f1[y]) . (I*E^(I*x))*
   Derivative[2][f2][y] . E^(2*I*x) + 
 Derivative[1][f1][y] . (I*E^(I*x))*
   Derivative[1][g2][y] + (-f1[y]) . (I*E^(I*x))*
   Derivative[2][g2][y];

Newlist = List @@ eqn;

For[i = 1, i < Length[Newlist] + 1, i++,


Terms = List @@ Newlist[[i]];
 Factor1 = Terms[[1]];
 Factor2 = Terms[[2]];

 Print[Factor1];
 Print[Factor2];

 ]

Here is my output from running this code

$\text{f1}'(y).e^{i x}$

$\text{f2}'(y).\left(2 i e^{2 i x}\right)$

$\text{f1}'(y).\left(i e^{i x}\right)$

and so on.

Most factors have a "." between the $f$ function and the $e^{m i x}$. I want to get rid of the period. I cannot get rid of the periods in the "eqn" definition as they are there for a specific reason. Here is what I have tried so far.

StringReplace["Factor1", "." -> ""]

Which outputs "Factor1" however, when I do this

StringReplace["f1'[y].e^{i x}","."->""]

It returns

$\text{f1}'(y)e^{i x}$

without the period how I want it.

My question is: How can I call Factor1 in the StringReplace without Mathematica thinking "Factor1" is the string and will replace it with the expression that it is equal to?

Thank you for any help

$\endgroup$
3
  • 2
    $\begingroup$ does this give the desired output: List @@@ List @@ eqn /. Dot -> Times? $\endgroup$
    – kglr
    Commented Apr 1, 2020 at 3:16
  • $\begingroup$ @kglr That worked great, thanks. I put that line of code right after NewList = and it sorted my terms and took out the periods giving the desired output. $\endgroup$ Commented Apr 1, 2020 at 3:45
  • $\begingroup$ Carlos, posted the comment as an answer. $\endgroup$
    – kglr
    Commented Apr 1, 2020 at 4:24

1 Answer 1

3
$\begingroup$
result = List @@@ List @@ eqn /. Dot -> Times

TeXForm @ Column @ result

$\begin{array}{l} \left\{e^{i x} \text{f1}'(y),2 i e^{2 i x} \text{f2}'(y)\right\} \\ \left\{i e^{i x} \text{f1}'(y),e^{2 i x} \text{f2}'(y)\right\} \\ \left\{\text{f3}'(y),3 i e^{3 i x}\right\} \\ \left\{\text{g3}'(y),i e^{i x}\right\} \\ \left\{-2 i e^{2 i x} \text{f2}(y),e^{i x} \text{f1}''(y)\right\} \\ \left\{-i e^{i x} \text{f1}(y),e^{2 i x} \text{f2}''(y)\right\} \\ \left\{i e^{i x} \text{f1}'(y),\text{g2}'(y)\right\} \\ \left\{-i e^{i x} \text{f1}(y),\text{g2}''(y)\right\} \\ \end{array}$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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