2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ The intersection is the point where both lines meet. What difficulties do you have to see it? $\endgroup$ – Dr. belisarius May 1 '13 at 1:43
  • $\begingroup$ 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 ? mathematica.stackexchange.com/questions/10472/…. $\endgroup$ – user7210 May 1 '13 at 1:53
  • $\begingroup$ @user7210 are you looking for more than is in my answer? $\endgroup$ – Jonathan Shock May 3 '13 at 1:19
3
$\begingroup$

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}]]
$\endgroup$
1
$\begingroup$
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

$\endgroup$
0
$\begingroup$

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

$\endgroup$

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.