Message Boards Message Boards


Plot complex solution obtained using DSolve?

Posted 7 months ago
7 Replies
0 Total Likes

Hi, I need to plot this stuff, but unfortunately that doesn't work and I don't understand why. If someone could help me?

diffeq3 = x3''[t] + 10*x3[t] + 0.5*(x3[t] - x4[t]) == 0

diffeq4 = x4''[t] + 10*x4[t] + 0.5*(x4[t] - x3[t]) == 0

sol1 := DSolve[{diffeq3, diffeq4, x3'[0] == 0, x4'[0] == 0, 
    x3[0] == xo3, x4[0] == xo4}, {x3[t], x4[t]}, t];

posx3[t_, xo3_, xo4_] = x3[t] /. sol1;

posx4[t_, xo3_, xo4_] = x4[t] /. sol1;

Plot[{posx3[t, 1, -1], posx4[t, 1, -1]}, {t, 0, 40}]

The problem is at the end of my file.

7 Replies


Your general solution to the differential equation has complex numbers which go to zero when you ask for solutions that are real. However, because of machine precision, you have some VERY small complex parts. For example,

In[20]:= posx3[0, 1, -1]

Out[20]= {1. + 1.38667*10^-32 I}

You must use Chop[] to get rid of infinitesimal imaginary parts. For example:

sol1 := Chop[DSolve[{diffeq3, diffeq4, x3'[0] == 0, x4'[0] == 0, x3[0] == xo3, x4[0] == xo4}, {x3[t], x4[t]}, t]];

will fix this by Choping the numbers when evaluating posx3, posx4 or you can Chop it later at Plot time.



Posted 7 months ago

ty mate

See my adjustments.

Tested on:

(* "11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)" *)

(* "10.2.0 for Microsoft Windows (64-bit) (July 7, 2015)"  *)
Posted 7 months ago

Ty mate

Posted 7 months ago

Thank u both

Posted 7 months ago

Well that doesn't work again. Wich version of the software have u got ? Because mine is 11.0 Student Version and i think my version isn t updated or kind of.

See my updated.

Read this it can help you.

Reagards, MI

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract