Difference between revisions of "ContourPlots"

From WeBWorK_wiki
Jump to navigation Jump to search
(New page: <h2>Contour Plots</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This PG code shows how...)
 
(added historical tag and gave updated problem link)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/DiffCalcMV/ContourPlot.html a newer version of this problem]</p>
 
<h2>Contour Plots</h2>
 
<h2>Contour Plots</h2>
   
Line 166: Line 169:
 
[[IndexOfProblemTechniques|Problem Techniques Index]]
 
[[IndexOfProblemTechniques|Problem Techniques Index]]
 
</p>
 
</p>
  +
  +
  +
  +
<ul>
  +
<li>POD documentation: [http://webwork.maa.org/pod/pg/macros/PGgraphmacros.html PGgraphmacros.pl]</li>
  +
<li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/PGgraphmacros.pl?view=log PGgraphmacros.pl]</li>
  +
</ul>
  +
  +
  +
<ul>
  +
<li>POD documentation: [http://webwork.maa.org/pod/pg/lib/WWPlot.html WWPlot.pm]</li>
  +
<li>PG library file: [http://webwork.maa.org/viewvc/system/trunk/pg/lib/WWPlot.pm?view=log WWPlot.pm]</li>
  +
</ul>
   
 
[[Category:Problem Techniques]]
 
[[Category:Problem Techniques]]

Latest revision as of 10:51, 29 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

Contour Plots


This PG code shows how to construct contour plots.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGgraphmacros.pl",
"unionTables.pl",
);

TEXT(beginproblem());

$refreshCachedImages=1;

Initialization: Use unionTables.pl to display the graphs nicely.

Context("Numeric")->variables->are(x=>"Real",y=>"Real");

#
#  Create some graph canvases
#
foreach my $i (0..1) {
  $gr[$i] = init_graph(-5,-5,5,5,grid=>[10,10],axes=>[0,0],pixels=>[400,400]);
  $gr[$i]->lb('reset');
  $gr[$i]->lb( new Label(4.7,0.2,'x','black','center','middle'));
  $gr[$i]->lb( new Label(0.2,4.7,'y','black','center','middle'));
  $gr[$i]->new_color("nicegreen",0,110,0); # verdant green
  $gr[$i]->new_color("darkred", 159, 64, 16); # red-brown
}

#
#  Circular contours as parametrized curves
#
foreach $k (5,10,15,20,25,30,35,40,45) {
  my $a = sqrt($k);
  $fn = new Fun( 
     sub { my $t=shift(); return $a * cos($t); }, 
     sub { my $t=shift(); return $a * sin($t);}, 
     $gr[0] 
  );
  $fn->domain(0,6.3);
  $fn->color("nicegreen");
}

#
#  Hyperbolas as parametrized curves
#
foreach my $k (0,5,10,15,20,25) {
  # left and right branches
  $fn = new Fun( 
     sub { my $t=shift(); return sqrt($k+$t**2); }, 
     sub { my $t=shift(); return $t;}, 
     $gr[1] 
  );
  $fn->domain(-5,5);
  $fn->color("darkred");
  $fn = new Fun( 
     sub { my $t=shift(); return -sqrt($k+$t**2); }, 
     sub { my $t=shift(); return $t;}, 
     $gr[1] 
  );
  $fn->domain(-5,5);
  $fn->color("darkred");

  # top and bottom branches
  add_functions($gr[1],
  " sqrt(x^2+$k)  for x in <-5,5> using color:darkred and weight:2",
  "-sqrt(x^2+$k)  for x in <-5,5> using color:darkred and weight:2",
  );
}

foreach my $i (0..1) {
  $fig[$i] = image(insertGraph($gr[$i]),width=>300,height=>300,tex_size=>450);
}

Setup: We create the contour plots as a parametrized family of (parametric) curves.

BEGIN_TEXT
$BCENTER
\{
BeginTable().
AlignedRow([$fig[0],$fig[1]]).
TableSpace(5,0).
AlignedRow(["A","B"]).
EndTable();
\}
$BR
(Click on a graph to enlarge it.)
$ECENTER
END_TEXT

Main Text: We display the contour plots nicely using tables provided by unionTables.pl.

$showPartialCorrectAnswers = 1;

ENDDOCUMENT();

Answer Evaluation: We did not ask any questions, so there's nothing interesting here.

Problem Techniques Index