There are no issues trying to find the intersection points of two defined curves.
f[x_] := 2 (x - 1) (x - 1.5) (x - .5) (x + .5) (x + 1) (x + 1.5);
g[x_] := 0.4 x - 0.4;
Solve[f[x] == g[x], x]
(*{{x -> -1.39849}, {x -> -1.20949}, {x -> -0.331841}, {x ->
0.426865}, {x -> 1.}, {x -> 1.51295}}*)
Manipulate[Plot[Evaluate[{f[x], g[x]}], {x, -1.5, 1.52},
Epilog -> {Red, PointSize[Large],
Point[{#, f[#]} & /@ (x /.
Solve[f[x] == g[x], x])]}], {a, -0.8, .5, .2}]
When I try to perform the same but this time with an interpolation function I run into problems.
points = Table[{x, f[x]}, {x, -1.5, 1.5, .25}];
if = Interpolation[points];
I can obtain the first intersection by using the following.
Neither NSolve nor Solve will work with interpolation function.
With Solve this will happen
Solve[if[x] == g[x], x]
Solve::inex: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >>
With NSolve, you get a similar error.
NSolve[if[x] == g[x], x, Reals]
(NSolve[InterpolatingFunction[{{-1.5,1.5}},<>][x]==-0.4+0.4 x,x,Reals])
FindRoot[if[x] == g[x], {x, -1.5}]
(*{x -> -1.36794}*)
Which makes this question different from marking points of intersections between two curves as the problem is specific when using InterpolationFunction
What is the best way to find all intersection points between the range (-1.5 and 1.5)?