0
$\begingroup$

I'm starting using Mathematica. I have two coupled differential equations and after using NDSolve the output is in the form of a Interpolating Function. I want to Plot the square modulus of one of the two solutions, but after several trials the plot is still empty. I want to know how to work with this function.

sol = NDSolve[{a1'[t] == -I*V12*Exp[-I*w21*t]*a2[t], 
 a2'[t] == -I*V21*Exp[I*w21*t]*a2[t], a1[0] == 1, a2[0] == 0},
 {a1, a2}, {t, 40}] 

(* {{a1->InterpolatingFunction[{{0.,40.}},"<>"],
  a2->InterpolatingFunction[{{0.,4‌​0.}},"<>"]}}    *)  

f1=a1->InterpolatingFunction[{{0.,40.}},"<>"]      

f2 = Conjugate[fun] // ComplexExpand 
f3 = fun*gun Plot[f3, {t, 0, 40}]

Where fun is f1 and gun is f2.

$\endgroup$
  • $\begingroup$ Post the code of your attempts. $\endgroup$ – ciao Apr 15 '14 at 7:24
  • $\begingroup$ sol = NDSolve[{a1'[t] == -IV12*Exp[-Iw21*t]*a2[t], a2'[t] == -IV21*Exp[Iw21*t]*a2[t], a1[0] == 1, a2[0] == 0}, {a1, a2}, {t, 40}] {{a1->InterpolatingFunction[{{0.,40.}},"<>"],a2->InterpolatingFunction[{{0.,40.}},"<>"]}} $\endgroup$ – user13722 Apr 15 '14 at 7:32
  • $\begingroup$ f1=a1->InterpolatingFunction[{{0.,40.}},"<>"] $\endgroup$ – user13722 Apr 15 '14 at 7:33
  • $\begingroup$ f2 = Conjugate[fun] // ComplexExpand f3 = fun*gun Plot[f3, {t, 0, 40}] I think I have no idea what I am doing $\endgroup$ – user13722 Apr 15 '14 at 7:34
  • $\begingroup$ I'm sorry fun is f1 and gun is f2 $\endgroup$ – user13722 Apr 15 '14 at 7:41
3
$\begingroup$

I can't make heads or tails of above, but perhaps this will get you started. Read the documentation - it's your best source of information.

First, let's get some solution from NDSolve :

sol =  NDSolve[{u''[t] + u[t] == 0, u[0] == 0, u'[0] == 1}, u, {t, 0, \[Pi]}]

(* {{u->InterpolatingFunction[{{0.,3.14159}},<>]}} *)

So, NDSolve has given us a set of Rules (in this case, just one) that maps the solution for u to an InterpolatingFunction. Read the documentation re: rules if you are new to the concept.

So, we'll take that rule and extract the function itself into a convenient name:

interpFN = u /. First@sol

(* InterpolatingFunction[{{0.,3.14159}},<>] *)

We can use this (pretty much) like any other function:

interpFN[2]
(* 0.909297 *)

And plot it in the same way:

Plot[interpFN[x], {x, 0, Pi}]

enter image description here

Hope that helped somewhat...

$\endgroup$
  • $\begingroup$ Thanks for answer!, but what about if I want to plot the square modulus of "u" assuming that is a complex function? I can conjugate individual points of the Interpolating function, but I fail conjugating the whole function $\endgroup$ – user13722 Apr 16 '14 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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