Group Abstract Group Abstract

Message Boards Message Boards

[?] Separate out the real and imaginary part and export data?

POSTED BY: Sreeraj T
6 Replies

Hey Sreeraj,

which version of Mathematica are you using? ReIm is a function the was introduced in 10.1 and I always forget to mention that my code runs on the latest version 11.1. In this case, the fix is easy, define the ReIm function yourself

ReIm[x_?NumericQ] := {Re[x], Im[x]};
ReIm[x_] := x;

As for your other question, this can easily be done, but you have to remember, that your root might be a complex number. Let's say you want to plot your k against the real part of the first root, you can use:

data = Table[Flatten@{k, roots}, {k, 0.01, 1, .01}];
ListPlot[Re@data[[All, {1, 2}]]]

Mathematica graphics

POSTED BY: Patrick Scheibe
POSTED BY: Sreeraj T

It means: take All values from the 1st and 2nd column of data and calculate their Real part. Since your k are real anyway it doesn't matter and from the first roots (in the 2nd column) all real parts are taken. This is then plotted, which gives you a graph of k against the real-part of the first root.

POSTED BY: Patrick Scheibe

Thanks a lot Patrick Scheibe. And sorry for delay in replying...

POSTED BY: Sreeraj T

From an analytical point of view, you should really consider solving your equation analytically. This can be done by

    ClearAll["Global`*"]
    first = 1 + 17000000/k^2 + 5000000/k^2 + 868670/k^2;
    second = 14000/w^2 + (5000000 w^2)/(k^2*(w^2 - 1));
    third = Rationalize[600/(w - 0.01)^2 + (400000 (w - 0.01)^2)/(k^2*0.125 ((w - 0.01)^2 - 0.25))];
    roots = w /. Solve[first - second - third == 0, w];

If you look at roots you see that it contains Root objects with unspecified k. This is perfectly fine, since we can evaluate them by plugging in values for k inside your Table. Since you are interested in a separation of real and imaginary part, we can do this directly in the table by using ReIm. Flattening out the result, gives you exactly what you want to export as one line: the k in the front and then all roots.

data = Table[Flatten@{k, ReIm /@ roots}, {k, 0.01, 1, .01}];
Export["tmp/roots.dat", data, "Table"]

That should be it.

POSTED BY: Patrick Scheibe
POSTED BY: Sreeraj T
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard