﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?application progid="SMath Studio" version="0.88"?>
<regions>
  <settings>
    <editable>true</editable>
    <metadata lang="eng">
      <title>Implicit-function graphing routine</title>
      <author>Anonymous</author>
      <description>Algorithm to graph implicit functions of 2 variables.  
This is useful for graphing equations f(x,y)=K (where K is a constant) that are difficult or impossible to separate into a 1-variable function y=F(x).  
This can also be used to make contour plots of a 3-dimensional function z=f(x,y).  </description>
      <company />
      <keywords>Examples, 2-D Contour Graphs</keywords>
    </metadata>
    <calculation>
      <functions>1</functions>
      <precision>4</precision>
      <angle>radians</angle>
      <fractions>decimal</fractions>
      <recalculation>true</recalculation>
    </calculation>
    <dependences>
      <assembly name="SMath Studio" version="0.88" guid="a37cba83-b69c-4c71-9992-55ff666763bd" />
      <assembly name="Special Functions" version="1.1.3753.43100" guid="2814e667-4e12-48b1-8d51-194e480eabc5" />
    </dependences>
  </settings>
  <region id="0" left="9" top="9" width="566" height="28" color="#0000ff" background-color="#ffffff" font-size="12">
    <text lang="eng">
      <p bold="false" href="">What kind of problem can this example be used to solve?  </p>
    </text>
  </region>
  <region id="1" left="9" top="45" width="783" height="296" border="true" color="#000000" background-color="#ffffff" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Suppose you want to plot an equation that has 2 variables (they might be called x and y) and, if the equation is described as LeftSide = RightSide, neither LeftSide nor RightSide is 0.  For example, sin(2*x)*cos(y) = 0.4Then write this equation with either LeftSide or RightSide subtracted from both sides so that the equation looks like LeftSide-RightSide=0 (or RightSide-LeftSide=0)In the above example, you could subtract 0.4 to get:  sin(2*x)*cos(y)-0.4 = 0Then define a function which equals (in this example) LeftSide-RightSide.  When this function = 0, your original equation is true.The equation needs to be written "= 0" because the implicit-function grapher is designed to plot the points where some expression (the function given by you) = 0.  If there was originally a function z=Funct(x,y), such as z=sin(2*x)*cos(y) in the above example, then graphing Funct(x,y) = K, which is Funct(x,y)-K = 0, where K is a constant, makes part of a contour plot of Funct.  </p>
    </text>
  </region>
  <region id="2" left="9" top="351" width="595" height="24" border="true" color="#000000" background-color="#ffffff" font-size="10">
    <text lang="eng">
      <p bold="false" href="">This example is based on http://twt.mpei.ac.ru/ochkov/Lace/Lace_eng.htm</p>
    </text>
  </region>
  <region id="3" left="9" top="378" width="142" height="28" color="#0000ff" background-color="#ffffff" font-size="12">
    <text lang="eng">
      <p bold="false" href="">Definitions:  </p>
    </text>
  </region>
  <region id="4" left="9" top="405" width="233" height="24" border="true" color="#000000" background-color="#c0c0c0" font-size="10">
    <text lang="eng">
      <p bold="false" href="">The function to be plotted:</p>
    </text>
  </region>
  <region id="5" left="18" top="432" width="229" height="26" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">x</e>
        <e type="operand">y</e>
        <e type="function" args="2">f</e>
        <e type="operand">2</e>
        <e type="operand">x</e>
        <e type="operator" args="2">*</e>
        <e type="function" args="1">sin</e>
        <e type="operand">y</e>
        <e type="function" args="1">cos</e>
        <e type="operator" args="2">*</e>
        <e type="operand">0.4</e>
        <e type="operator" args="2">-</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="6" left="9" top="477" width="499" height="40" border="true" color="#000000" background-color="#c0c0c0" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Specify what region of the input variables you want to plot (generically, we'll call these variables x and y):  </p>
    </text>
  </region>
  <region id="7" left="36" top="531" width="77" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">xmin</e>
        <e type="operand">3</e>
        <e type="operator" args="1">-</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="8" left="180" top="531" width="68" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">xmax</e>
        <e type="operand">3</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="9" left="306" top="531" width="77" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">ymin</e>
        <e type="operand">3</e>
        <e type="operator" args="1">-</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="10" left="450" top="531" width="68" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">ymax</e>
        <e type="operand">3</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="11" left="9" top="567" width="463" height="24" border="true" color="#000000" background-color="#c0c0c0" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Specify the fineness of display resolution of the plot:</p>
    </text>
  </region>
  <region id="12" left="18" top="603" width="101" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">xstep</e>
        <e type="operand">0.02</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="13" left="135" top="603" width="101" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">ystep</e>
        <e type="operand">0.02</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="14" left="9" top="639" width="341" height="28" color="#0000ff" background-color="#ffffff" font-size="12">
    <text lang="eng">
      <p bold="false" href="">How big is the graphing problem?  </p>
    </text>
  </region>
  <region id="15" left="9" top="666" width="749" height="24" border="true" color="#000000" background-color="#c0c0c0" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Based on the above constants, let's find out how many points will be potentially graphed:  </p>
    </text>
  </region>
  <region id="16" left="27" top="702" width="180" height="43" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">xsize</e>
        <e type="operand">xmax</e>
        <e type="operand">xmin</e>
        <e type="operator" args="2">-</e>
        <e type="bracket">(</e>
        <e type="operand">xstep</e>
        <e type="operator" args="2">/</e>
        <e type="operand">1</e>
        <e type="operator" args="2">+</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="17" left="396" top="702" width="180" height="43" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">ysize</e>
        <e type="operand">ymax</e>
        <e type="operand">ymin</e>
        <e type="operator" args="2">-</e>
        <e type="bracket">(</e>
        <e type="operand">ystep</e>
        <e type="operator" args="2">/</e>
        <e type="operand">1</e>
        <e type="operator" args="2">+</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="18" left="252" top="711" width="103" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math optimize="1">
      <input>
        <e type="operand">xsize</e>
      </input>
      <result action="numeric">
        <e type="operand">301</e>
      </result>
    </math>
  </region>
  <region id="19" left="612" top="711" width="103" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math optimize="1">
      <input>
        <e type="operand">ysize</e>
      </input>
      <result action="numeric">
        <e type="operand">301</e>
      </result>
    </math>
  </region>
  <region id="20" left="18" top="756" width="167" height="24" color="#000000" background-color="#ffffff" font-size="10">
    <math optimize="1">
      <input>
        <e type="operand">xsize</e>
        <e type="operand">ysize</e>
        <e type="operator" args="2">*</e>
      </input>
      <result action="numeric">
        <e type="operand">90601</e>
      </result>
    </math>
  </region>
  <region id="21" left="234" top="756" width="356" height="24" color="#000000" background-color="#ffff80" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Total number of points potentially graphed</p>
    </text>
  </region>
  <region id="22" left="9" top="792" width="531" height="24" border="true" color="#000000" background-color="#c0c0c0" font-size="10">
    <text lang="eng">
      <p bold="false" href="">(Scroll down for the implicit-function graphing routine itself)</p>
    </text>
  </region>
  <region id="23" left="9" top="999" width="399" height="28" color="#0000ff" background-color="#ffffff" font-size="12">
    <text lang="eng">
      <p bold="false" href="">The implicit-function graphing routine:</p>
    </text>
  </region>
  <region id="24" left="9" top="1026" width="794" height="408" color="#000000" background-color="#ffff80" font-size="10">
    <text lang="eng">
      <p bold="false" href="">It works by computing the value of the function at and near each one of the xsize*ysize points, scanning across the specified region (of the input variables) in grid fashion.  The value ("Pvalue") at each point P is multiplied by the value ("Qvalue") at a point Q that is close to point P (distance "xstep" away from P).   - If P or Q is a root of the equation, then Pvalue or Qvalue is 0, so Pvalue * Qvalue = 0.   - If a root is between P and Q, then, typically, one of Pvalue or Qvalue is positive and the other is negative, so Pvalue * Qvalue &lt; 0.   This requires that:        (a) xstep is small enough so that no other roots are between P and Q, and       (b) there does not happen to be a root between P and Q that is also a local maximum or                minimum [example:  if f(x)=x^2 and P is at x=-1 and Q is at x=+1, then Pvalue and Qvalue                are both positive, even though there is a root x=0 between P and Q].  So if Pvalue * Qvalue &lt;= 0, the coordinates (x,y) of P are added (concatenated) to a list of points to plot.  The same procedure that has just been described for points P and Q is also done for points P and R, where R is close in the y-direction (by distance ystep) to point P.  If only P and Q were considered, then nearly horizontal parts of the graph might not have as many points, which would make them harder to see.  The names P, Q, R are used only in this text, not in the graphing routine itself.    P is (x, y)  Q is (x-xstep, y)   R is (x, y-ystep) </p>
    </text>
  </region>
  <region id="25" left="9" top="1449" width="109" height="26" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">Points</e>
        <e type="operand">0</e>
        <e type="operand">0</e>
        <e type="operand">1</e>
        <e type="operand">2</e>
        <e type="function" args="4">mat</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="26" left="135" top="1449" width="619" height="56" color="#000000" background-color="#ffff80" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Initialize the list of points to plot; otherwise, when the first point is to be added, the software won't be able to detect the dimensions of the list and will indicate an error.</p>
    </text>
  </region>
  <region id="27" left="9" top="1512" width="478" height="114" color="#000000" background-color="#ffffff" font-size="10">
    <math optimize="2">
      <input>
        <e type="operand">y</e>
        <e type="operand">ymin</e>
        <e type="operand">ymax</e>
        <e type="operand">ymin</e>
        <e type="operand">ystep</e>
        <e type="operator" args="2">+</e>
        <e type="function" args="3">range</e>
        <e type="operand">x</e>
        <e type="operand">xmin</e>
        <e type="operand">xmax</e>
        <e type="operand">xmin</e>
        <e type="operand">xstep</e>
        <e type="operator" args="2">+</e>
        <e type="function" args="3">range</e>
        <e type="operand">x</e>
        <e type="operand">xstep</e>
        <e type="operator" args="2">-</e>
        <e type="operand">y</e>
        <e type="function" args="2">f</e>
        <e type="operand">x</e>
        <e type="operand">y</e>
        <e type="function" args="2">f</e>
        <e type="operator" args="2">*</e>
        <e type="operand">0</e>
        <e type="operator" args="2">≤</e>
        <e type="bracket">(</e>
        <e type="operand">x</e>
        <e type="operand">y</e>
        <e type="function" args="2">f</e>
        <e type="operand">x</e>
        <e type="operand">y</e>
        <e type="operand">ystep</e>
        <e type="operator" args="2">-</e>
        <e type="function" args="2">f</e>
        <e type="operator" args="2">*</e>
        <e type="operand">0</e>
        <e type="operator" args="2">≤</e>
        <e type="bracket">(</e>
        <e type="operator" args="2">|</e>
        <e type="bracket">(</e>
        <e type="operand">Points</e>
        <e type="operand">Points</e>
        <e type="operand">x</e>
        <e type="operand">y</e>
        <e type="operand">1</e>
        <e type="operand">2</e>
        <e type="function" args="4">mat</e>
        <e type="function" args="2">stack</e>
        <e type="operator" args="2">←</e>
        <e type="operand">1</e>
        <e type="function" args="3">if</e>
        <e type="function" args="3">for</e>
        <e type="function" args="3">for</e>
      </input>
    </math>
  </region>
  <region id="28" left="585" top="1557" width="298" height="26" color="#000000" background-color="#ffffff" font-size="10">
    <math optimize="1">
      <input>
        <e type="operand">ymin</e>
        <e type="operand">ymax</e>
        <e type="operand">ymin</e>
        <e type="operand">ystep</e>
        <e type="operator" args="2">+</e>
        <e type="function" args="3">range</e>
        <e type="function" args="1">rows</e>
      </input>
      <result action="numeric">
        <e type="operand">301</e>
      </result>
    </math>
  </region>
  <region id="29" left="108" top="1629" width="474" height="40" color="#000000" background-color="#ffff80" font-size="10">
    <text lang="eng">
      <p bold="false" href="">A dummy "else" clause is used because it was not evident how to specify an "if" with no "else."</p>
    </text>
  </region>
  <region id="30" left="9" top="1674" width="393" height="28" color="#000000" background-color="#ffffff" font-size="10">
    <math fraction-type="none" optimize="1">
      <input>
        <e type="operand">Points</e>
        <e type="operand">Points</e>
        <e type="operand">2</e>
        <e type="operand">Points</e>
        <e type="function" args="1">rows</e>
        <e type="operand">1</e>
        <e type="operand">2</e>
        <e type="function" args="5">submatrix</e>
        <e type="operator" args="2">←</e>
      </input>
    </math>
  </region>
  <region id="31" left="72" top="1701" width="677" height="72" color="#000000" background-color="#ffff80" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Remove the first "point" that was added when the list of points was initialized. This will NOT erase the point (0, 0), if it happened to be found as a root of the equation or found to be near a root - any (0, 0) that was found will still appear in the list.</p>
    </text>
  </region>
  <region id="32" left="9" top="1782" width="251" height="24" border="true" color="#000000" background-color="#c0c0c0" font-size="10">
    <text lang="eng">
      <p bold="false" href="">(Scroll down for the results)</p>
    </text>
  </region>
  <region id="33" left="9" top="1998" width="86" height="24" border="true" color="#000000" background-color="#c0c0c0" font-size="10">
    <text lang="eng">
      <p bold="false" href="">Results:  </p>
    </text>
  </region>
  <region id="34" left="0" top="2025" width="164" height="26" color="#000000" background-color="#ffffff" font-size="10">
    <math optimize="1">
      <input>
        <e type="operand">Points</e>
        <e type="function" args="1">rows</e>
      </input>
      <result action="numeric">
        <e type="operand">1188</e>
      </result>
    </math>
  </region>
  <region id="35" left="126" top="2052" width="639" height="24" color="#000000" background-color="#ffff80" font-size="10">
    <text lang="eng">
      <p bold="false" href="">The number of points that were found to be roots, or to have roots near them.</p>
    </text>
  </region>
  <region id="36" left="54" top="2106" width="437" height="257" color="#000000" background-color="#ffffff" font-size="10">
    <plot type="2d" render="points" scale_x="3,34973530705441" scale_y="3,34973530705441" scale_z="3,34973530705441" rotate_x="0" rotate_y="0" rotate_z="0" transpose_x="-17" transpose_y="1" transpose_z="0">
      <input>
        <e type="operand">Points</e>
      </input>
    </plot>
  </region>
</regions>