Skip to main content
update the code to make it work in newer versions.
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

Update 3: Using Graphics`Mesh`FindIntersections to get the intersection points (see also):

showIntersections = Show[#
  Block[{Annotation = # &}, Graphics 
 @   Show[#, Graphics@{Red, PointSize[Large], 
      Point @ Graphics`Mesh`FindIntersections @ #Point@Graphics`Mesh`FindIntersections@#}]]] &;

Using the two examples in the original answer:

Row[showIntersections /@ {Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
    ImageSize -> 400],
   Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, ImageSize -> 400, 
    Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]}]

enter image description here

Original answer:

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)

Update 3: Using Graphics`Mesh`FindIntersections to get the intersection points (see also):

showIntersections = Show[#, Graphics @{Red, PointSize[Large], 
      Point @ Graphics`Mesh`FindIntersections @ #}] &;

Using the two examples in the original answer:

Row[showIntersections /@ {Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
    ImageSize -> 400],
   Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, ImageSize -> 400, 
    Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]}]

enter image description here

Original answer:

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)

Update 3: Using Graphics`Mesh`FindIntersections to get the intersection points (see also):

showIntersections = 
  Block[{Annotation = # &},  
    Show[#, Graphics@{Red, PointSize[Large], 
       Point@Graphics`Mesh`FindIntersections@#}]] &;

Using the two examples in the original answer:

Row[showIntersections /@ {Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
    ImageSize -> 400],
   Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, ImageSize -> 400, 
    Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]}]

enter image description here

Original answer:

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)
added 620 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Update 3: Using Graphics`Mesh`FindIntersections to get the intersection points (see also):

showIntersections = Show[#, Graphics @{Red, PointSize[Large], 
      Point @ Graphics`Mesh`FindIntersections @ #}] &;

Using the two examples in the original answer:

Row[showIntersections /@ {Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
    ImageSize -> 400],
   Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, ImageSize -> 400, 
    Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]}]

enter image description here

Original answer:

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update:Update: Dealing with Tan[x] using Exclusions

Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2:Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)

Update 3: Using Graphics`Mesh`FindIntersections to get the intersection points (see also):

showIntersections = Show[#, Graphics @{Red, PointSize[Large], 
      Point @ Graphics`Mesh`FindIntersections @ #}] &;

Using the two examples in the original answer:

Row[showIntersections /@ {Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
    ImageSize -> 400],
   Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, ImageSize -> 400, 
    Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]}]

enter image description here

Original answer:

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)
added 337 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

  Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

  Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

You can also use MeshFunctions:

  Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
     MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]]

plot of Cos[x] and x Sin[x]

Update: Dealing with Tan[x] using Exclusions

Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, 
   MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
   (* or Exclusions -> (Cos[x] == 0) *)

plot of Tan[x] and x Sin[x]

Update 2: Using just Mesh and MeshStyle:

points = NSolve[Tan[x] == x Sin[x] && -3 Pi < x < 3 Pi, x][[All, 1, 2]];
Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi},
  Mesh -> {points},
  MeshStyle -> {Directive[Red, PointSize[Large]]},
  Exclusions -> Range[-5 Pi/2, 5 Pi/2, Pi]]
(* same picture as above *)
deleted 16 characters in body
Source Link
Loading
deleted 242 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 658 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading