Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot implicit equations

What is the usual method or algorithm used to plot implicit equations of 2 variables?

I am talking about equations such as,

sin(x*y)*y = 20

x*x - y*y = 1

Etc.

Does anyone know how Maple or Matlab do this? My target language is C#.

Many thanks!

like image 508
ARV Avatar asked Jul 15 '09 14:07

ARV


2 Answers

One way to do this is to sample the function on a regular, 2D grid. Then you can run an algorithm like marching squares on the resulting 2D grid to draw iso-contours.

In a related question, someone also linked to the gnuplot source code. It's fairly complex, but might be worth going through. You can find it here: http://www.gnuplot.info/

like image 192
Eric Avatar answered Sep 30 '22 08:09

Eric


Iterate the value of x across the range you want to plot. For each fixed value of x, solve the equation numerically using a method such as interval bisection or the Newton-Raphson method (for which you can calculate the derivative using implicit differentiation, or perhaps differentiate numerically). This will give you the corresponding value of y for a given x. In most cases, you won't need too many iterations to get a very precise result, and it's very efficient anyway.

Note that you will need to transform the equation into the form f(x) = 0, though this is always trivial. The nice thing about this method is that it works just as well the other way round (i.e. taking a fixed range of y and computing x per value).

like image 44
Noldorin Avatar answered Sep 30 '22 08:09

Noldorin