6

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#.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
ARV
  • 6,287
  • 11
  • 31
  • 41

4 Answers4

11

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/

Eric
  • 6,364
  • 1
  • 32
  • 49
  • 2
    Thank you for providing the right keywords to search for. This search (http://www.google.com.sg/search?q=Marching+squares+contours) especially threw up some interesting links. – ARV Jul 15 '09 at 15:00
  • @ARV which of those interesting links solved your problem. Were you able to create a C# code successfully – MySchizoBuddy Sep 23 '14 at 15:29
7

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).

Noldorin
  • 144,213
  • 56
  • 264
  • 302
1

There're multiple methods. The easiest algorithm I could find is descripted here: https://homepages.warwick.ac.uk/staff/David.Tall/pdfs/dot1986b-implicit-fns.pdf and describes what Noldorin has described you.

The most complex one, and seems to be the one that can actually solve a lot of special cases is described here: https://academic.oup.com/comjnl/article/33/5/402/480353

Georg Friedrich
  • 183
  • 2
  • 12
-2

i think,

in matlab you give array as input for x.

then for every x, it calculates y.

then draws line from x0,y0 to x1, y1

then draws line from x1,y1 to x2, y2

...

...

ufukgun
  • 6,889
  • 8
  • 33
  • 55