2

Trying to plot the following two functions to show points of intersection.

2 x + y - 1 == 0, 
x - y + 2 == 0
ContourPlot[{2 x + y - 1 == 0, x - y + 2 == 0}, {x, -5, 5}, {y, -5, 5}]

The above shows the plots, but I find it difficult to see the point of intersection. I suspect that there is a better method than this.

Please suggest a good method to plot such equations.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user7210
  • 21
  • 1
  • 2
  • 1
    The intersection is the point where both lines meet. What difficulties do you have to see it? – Dr. belisarius May 01 '13 at 01:43
  • True. I am unable to highlight the point and show its co-ordinates. I have looked at an approach in the following question. Is there a similar method that can be used here ? http://mathematica.stackexchange.com/questions/10472/marking-points-of-intersection-between-two-curves. – user7210 May 01 '13 at 01:53
  • @user7210 are you looking for more than is in my answer? – Jonathan Shock May 03 '13 at 01:19

3 Answers3

4

If you want to know the value of the points then you can use Solve. If you want to be able to see the intersection point highlighted then you can add a point at that value of x and y:

eqs = {2 x + y - 1 == 0, x - y + 2 == 0}
sol = {x, y} /. Solve[eqs, {x, y}]
Show[ListPlot[sol, PlotStyle -> PointSize -> 0.02],ContourPlot[Evaluate[eqs], {x, -5, 5}, {y, -5, 5}]]
Jonathan Shock
  • 3,015
  • 15
  • 24
1
ContourPlot[{2 x + y - 1 == 0, x - y + 2 == 0}, {x, -5, 5}, {y, -5,  5}, 
 MeshFunctions -> {Function[{x, y}, 2 x + y - 1 - (x - y + 2)]}, 
 MeshStyle -> Directive[PointSize[Large], Red], Mesh -> {{0}}]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
0

You could put these linear equations in matrix form:

i = LinearSolve[a = {{2, 1}, {1, -1}}, b = {1, -2}]
ContourPlot[Evaluate@Thread[a.{x, y} == b], {x, -3, 3}, {y, -3, 3}, 
 Epilog -> {Red, PointSize[0.02], Point[i]}, 
 PlotLegends -> "Expressions"]

enter image description here

ubpdqn
  • 60,617
  • 3
  • 59
  • 148