[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /homework/templates Plot_data.problem

raeburn raeburn@source.lon-capa.org
Fri, 20 Aug 2010 03:54:56 -0000


raeburn		Fri Aug 20 03:54:56 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/homework/templates	Plot_data.problem 
  Log:
  - Backport 1.6.
  
  
Index: loncom/homework/templates/Plot_data.problem
diff -u loncom/homework/templates/Plot_data.problem:1.4 loncom/homework/templates/Plot_data.problem:1.4.8.1
--- loncom/homework/templates/Plot_data.problem:1.4	Mon Oct 29 16:21:07 2007
+++ loncom/homework/templates/Plot_data.problem	Fri Aug 20 03:54:56 2010
@@ -1,12 +1,19 @@
 <problem>
 
 <script type="loncapa/perl">
+#
+# This example populates arrays with the x and y coordinates of the plot.
+# For continuous functions, another approach is to use curve plots.
+#
 $amplitude = &random(1,4,0.5);
 $x_min = -5;
 $x_max =  5;
 for ($x=$x_min;$x<=$x_max;$x=$x+0.05) {
    push(@X,$x);
    push(@Y,$amplitude*sin($x));
+# Safeguard:
+# The following line limits the size of the array to 1000 to avoid infinite loops
+   if (($#X>1000) || ($#Y>1000)) { last; }
 }
 </script>