-1
$\begingroup$

After rather long and relatively complicated calcuations, I finally got to a point where all my $x(t)$ functions are

equationSolution = {0.015922 + (0.0000570403 - 
     0.000813858 I) C2 E^((-11.2868 - 344.474 I) t) + (0.0000570403 + 
     0.000813858 I) C1 E^((-11.2868 + 344.474 I) t) - (0.00277545 - 
     0.0208373 I) C6 E^((-5.40686 - 40.5931 I) t) - (0.00277545 + 
     0.0208373 I) C5 E^((-5.40686 + 40.5931 I) t) + (1.79914*10^-18 - 
     0.00355291 I) C4 E^((-1.42109*10^-14 - 
      162.498 I) t) + (1.79914*10^-18 + 
     0.00355291 I) C3 E^((-1.42109*10^-14 + 162.498 I) t), 
 0.015922 - (0.0000644748 - 
     0.00196777 I) C2 E^((-11.2868 - 344.474 I) t) - (0.0000644748 + 
     0.00196777 I) C1 E^((-11.2868 + 344.474 I) t) - (0.0016191 - 
     0.00862548 I) C6 E^((-5.40686 - 40.5931 I) t) - (0.0016191 + 
     0.00862548 I) C5 E^((-5.40686 + 
      40.5931 I) t) - (8.57858*10^-19 - 
     0.00355291 I) C4 E^((-1.42109*10^-14 - 
      162.498 I) t) - (8.57858*10^-19 + 
     0.00355291 I) C3 E^((-1.42109*10^-14 + 162.498 I) t), 
 0.015922 - (0.0000644748 - 
     0.00196777 I) C2 E^((-11.2868 - 344.474 I) t) - (0.0000644748 + 
     0.00196777 I) C1 E^((-11.2868 + 344.474 I) t) - (0.0016191 - 
     0.00862548 I) C6 E^((-5.40686 - 40.5931 I) t) - (0.0016191 + 
     0.00862548 I) C5 E^((-5.40686 + 
      40.5931 I) t) + (1.00256*10^-18 - 
     0.00355291 I) C4 E^((-1.42109*10^-14 - 
      162.498 I) t) + (1.00256*10^-18 + 
     0.00355291 I) C3 E^((-1.42109*10^-14 + 162.498 I) t), 
 0.015922 - (0.280997 + 
     0.010463 I) C2 E^((-11.2868 - 344.474 I) t) - (0.280997 - 
     0.010463 I) C1 E^((-11.2868 + 344.474 I) t) + (0.860855 + 
     0. I) C6 E^((-5.40686 - 40.5931 I) t) + (0.860855 + 
     0. I) C5 E^((-5.40686 + 40.5931 I) t) - (0.577339 + 
     1.69348*10^-16 I) C4 E^((-1.42109*10^-14 - 
      162.498 I) t) - (0.577339 - 
     1.69348*10^-16 I) C3 E^((-1.42109*10^-14 + 162.498 I) t), 
 0.015922 + (0.678573 + 
     0. I) C2 E^((-11.2868 - 344.474 I) t) + (0.678573 + 
     0. I) C1 E^((-11.2868 + 344.474 I) t) + (0.358889 + 
     0.0190875 I) C6 E^((-5.40686 - 40.5931 I) t) + (0.358889 - 
     0.0190875 I) C5 E^((-5.40686 + 40.5931 I) t) + (0.577339 + 
     0. I) C4 E^((-1.42109*10^-14 - 162.498 I) t) + (0.577339 + 
     0. I) C3 E^((-1.42109*10^-14 + 162.498 I) t), 
 0.015922 + (0.678573 + 
     8.32667*10^-17 I) C2 E^((-11.2868 - 344.474 I) t) + (0.678573 - 
     8.32667*10^-17 I) C1 E^((-11.2868 + 344.474 I) t) + (0.358889 + 
     0.0190875 I) C6 E^((-5.40686 - 40.5931 I) t) + (0.358889 - 
     0.0190875 I) C5 E^((-5.40686 + 40.5931 I) t) - (0.577339 + 
     2.27914*10^-16 I) C4 E^((-1.42109*10^-14 - 
      162.498 I) t) - (0.577339 - 
     2.27914*10^-16 I) C3 E^((-1.42109*10^-14 + 162.498 I) t)}

Where there are two problems. I can't replace constants C1->C6 with those values

constants = {0.0164507 - 2.02961 I, 0.0164507 + 2.02961 I, 
 2.20498*10^-16 - 1.71741*10^-16 I, 
 2.50228*10^-16 - 1.3643*10^-16 I, -0.0285463 - 
  0.465175 I, -0.0285463 + 0.465175 I}

And I can't plot the functions using

Plot[equationSolution[[1]], {t, 0, 5}]

Anybody has an idea what to do?

I know that normally I should post a working example, but the code is quite long - approximately 100 lines.

$\endgroup$
5
  • $\begingroup$ Why can't you replace the constants? + I would strongly recommend naming the constants with lower case letters ... $\endgroup$
    – Bichoy
    Commented Mar 27, 2016 at 19:59
  • $\begingroup$ @Bichoy doing equationSolution=equationSolution/.constants does not replace the C1 by it's value in the table constants. No idea why! The error says **{0.0164507 -2.02961 I,0.0164507 +2.02961 \ I,2.20498*10^-16-1.71741*10^-16 I,2.50228*10^-16-1.3643*10^-16 \ I,-0.0285463-0.465175 I,-0.0285463+0.465175 I} is neither a list of \ replacement rules nor a valid dispatch table, and so cannot be used \ for replacing. ** $\endgroup$
    – skrat
    Commented Mar 27, 2016 at 20:09
  • 3
    $\begingroup$ @skrat equationSolution=equationSolution/.Thread[{C1,C2,...}->constants] or on the rhs of /. you need to put a list of rules of the form {C1->...,C2->...,...} $\endgroup$
    – unlikely
    Commented Mar 27, 2016 at 20:10
  • $\begingroup$ @skrat unlikely comment above is the right way to do it ... $\endgroup$
    – Bichoy
    Commented Mar 27, 2016 at 20:12
  • $\begingroup$ @unlikely: yep, this works! $\endgroup$
    – skrat
    Commented Mar 27, 2016 at 20:13

1 Answer 1

2
$\begingroup$

You can use Symbol and MapIndexed to create a list of Rules for use in ReplaceAll on equationSolution.

eqs = equationSolution /. MapIndexed[Symbol["C" <> ToString@First@#2] -> #1 &, constants];

Then you can use ReIm in Plot to separate the real and imaginary parts of each equation. PlotStyle is used to give the same colour to each equations real and imaginary part while giving the imaginary part a Dashed line. LineLegend is used as a custom legend.

Plot[Evaluate[ReIm /@ eqs], {t, 0, .3},
 PlotRange -> Full,
 AxesLabel -> {t, None},
 PlotStyle -> (Sequence @@ {Directive[Thin, ColorData[1][#]], 
       Directive[Dashed, ColorData[1][#]]} & /@ Range[Length@eqs]),
 PlotLegends -> Column@{
    LineLegend@*Sequence @@ 
     Transpose[{ColorData[1][#], "Eq. " <> ToString@#} & /@ 
       Range[Length@eqs]],
    LineLegend[{Thin, Dashed}, {"Real", "Imaginary"}]
    },
 ImageSize -> Large]

enter image description here

However, the imaginary parts of the equations are very small so it may be worth plotting these in their own chart or use some of the two y-axis plot methods found here.

Hope this helps.

$\endgroup$

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