Search code examples
functionplotwolfram-mathematica

Mathematica - How do I show of intersections of two functions on plot?


I have defined the two functions:

f[x_] := 40*1.04^x

g[x_] := 150*0.9^x

And then I'm plotting them:

Plot[{f[x], g[x]}, {x, 0, 20}]

But how do I show the intersection(s) of such two functions?


Solution

  • f[x_] := 40*1.04^x
    g[x_] := 150*0.9^x
    
    sol = Quiet[Solve[f[x] == g[x], x]];
    xpts = x /. sol;
    ypts = f /@ xpts;
    
    Plot[{f[x], g[x]}, {x, 0, 20},
     Epilog -> {PointSize[0.02], Orange,
       Map[Point, Transpose[{xpts, ypts}]]}]