4
$\begingroup$

How do I plot the solutions of

Sum[cf1[[i, 2]] E^(-r cf1[[i, 1]]), {i, Length@cf1}] == 0

where

cf1 = {{0, -100}, {1, 10}, {2, 10}, {3, 110}}

as lines on the complex plane? The equation is an simple example of an internal rate of return problem. To restate, I know that FindRoot will give me the answer in reals. I want to demonstrate that, on the complex plane, the answer is much more, ahh..., complex.

$\endgroup$
  • $\begingroup$ What is r supposed to be? $\endgroup$ – J. M. will be back soon Oct 13 '16 at 13:38
  • $\begingroup$ r is the interest rate, the internal rate of return that makes the present value of these cashflows equal to zero under continuous compounding. $\endgroup$ – Nicholas G Oct 13 '16 at 13:50
  • $\begingroup$ ...and certainly those are supposed to be real; however, you want to know about complex solutions fo the resulting equation, then? $\endgroup$ – J. M. will be back soon Oct 13 '16 at 13:52
3
$\begingroup$

My try.

cf1 = {{0, -100}, {1, 10}, {2, 10}, {3, 110}};
f[r_] := Sum[cf1[[i, 2]]/E^(r*cf1[[i, 1]]), {i, Length[cf1]}]

sol[A_] := Chop@Normal[r /. NSolve[f[r] == 0, r]] /. C[1] -> A
(* A is Integer according to the ConditionalExpression that I get rid of with Normal *)

pts = Flatten[#, 1] &@Table[sol[a], {a, 0, 15}];

ListPlot[ReIm /@ pts, Frame -> True, PlotRange -> All, FrameLabel -> {"Re", "Im"}]

enter image description here

Those are only the complex solutions to the equation f[r] == 0.


If you want something "prettier", use the domainPlot function written by Simon Woods:

domainPlot[f, 3]

enter image description here

domainPlot[f, 1]

enter image description here

$\endgroup$
  • $\begingroup$ that is gorgeous, better than what I had in mind. $\endgroup$ – Nicholas G Oct 13 '16 at 14:46
  • $\begingroup$ Remember to upvote the excellent answer of Simon Woods that I linked in my post, after you gain enough reputation to do so. $\endgroup$ – corey979 Oct 13 '16 at 14:48
  • $\begingroup$ How do I show that as a Plot3D? $\endgroup$ – Nicholas G Oct 13 '16 at 14:58
  • 1
    $\begingroup$ Got it, Plot3D[ReIm@f[Complex[a, b]], {a, -3, 3}, {b, -3, 3}] $\endgroup$ – Nicholas G Oct 13 '16 at 15:20
  • $\begingroup$ But when I look closely, the resulting surface is actually two surfaces. What is happening? $\endgroup$ – Nicholas G Oct 13 '16 at 15:29
1
$\begingroup$
cf1 = {{0, -100}, {1, 10}, {2, 10}, {3, 110}};

f[r_] = Sum[cf1[[i, 2]] E^(-r cf1[[i, 1]]), {i, Length@cf1}] // Simplify;

Solve will provide exact solutions

sol[m_] = Solve[f[r] == 0, r] /. C[1] -> m // Normal // Simplify

(*  {{r -> 2/3 I (-1 + 3 m) π}, 
     {r -> 2/3 I (π + 3 m π)}, 
     {r -> 2 I m π + Log[11/10]}}

The solutions are three points in the complex plane for each integer m

Verifying the solutions

And @@ (f[r] == 0 /. sol[m] //
   FullSimplify[#, Element[m, Integers]] &)

(*  True  *)

Note that ReIm is Listable

Attributes[ReIm]

(*  {Listable, Protected}  *)

pts = ReIm[Table[r /. sol[m], {m, -2, 2}]];

ListPlot[Tooltip[pts],
 Frame -> True, Axes -> False,
 FrameLabel -> (Style[#, 14, Bold] & /@
    {"Re[r]", "Im[r]"}),
 PlotLegends -> Range[-2, 2]]

enter image description here

$\endgroup$
0
$\begingroup$

I took the answers from Solve and did the following:

t1 = Table[ReIm[-((2 I \[Pi])/3) + 2 I \[Pi] n], {n, -5, 10}];
t2 = Table[ReIm[(2 I \[Pi])/3 + 2 I \[Pi] n], {n, -5, 10}];
t3 = Table[ReIm[2 I \[Pi] n + Log[11/10]], {n, -5, 10}];
Show@Graphics[{Point[t1], Point[t2], Point[t3]},
  Axes -> True, AspectRatio -> 1/GoldenRatio]

It works but I was hoping for something prettier.

$\endgroup$
  • $\begingroup$ Try ListPlot[t1~Join~t2~Join~t3]. But what did you hope for? $\endgroup$ – Julien Kluge Oct 13 '16 at 13:54

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.