File:  [LON-CAPA] / loncom / homework / templates / Plot_data.problem
Revision 1.6: download - view: text, annotated - select for diffs
Sun Aug 1 14:15:12 2010 UTC (13 years, 10 months ago) by www
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, HEAD, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
Bandaid for Bug #6242: put a safeguard into the sample code

    1: <problem>
    2: 
    3: <script type="loncapa/perl">
    4: #
    5: # This example populates arrays with the x and y coordinates of the plot.
    6: # For continuous functions, another approach is to use curve plots.
    7: #
    8: $amplitude = &random(1,4,0.5);
    9: $x_min = -5;
   10: $x_max =  5;
   11: for ($x=$x_min;$x<=$x_max;$x=$x+0.05) {
   12:    push(@X,$x);
   13:    push(@Y,$amplitude*sin($x));
   14: # Safeguard:
   15: # The following line limits the size of the array to 1000 to avoid infinite loops
   16:    if (($#X>1000) || ($#Y>1000)) { last; }
   17: }
   18: </script>
   19: 
   20: <gnuplot width="300" transparent="off" samples="100" grid="on" font="9" bgcolor="xffffff" height="300" align="left" fgcolor="x000000" border="on" plottype="Cartesian" >
   21:     <axis xmin="$x_min" ymin="-5" xmax="$x_max" ymax="5" color="x000000" />
   22:     <xlabel>Label X</xlabel>
   23:     <ylabel>Label Y</ylabel>
   24:     <curve linestyle="linespoints" name="My Plot" pointtype="0" color="x000000">
   25:         <data>@X</data>
   26:         <data>@Y</data>
   27:     </curve>
   28: </gnuplot>
   29: 
   30: <startouttext />
   31: What is the amplitude of this function?
   32: <endouttext />
   33: 
   34: <numericalresponse answer="$amplitude" format="2s">
   35:     <responseparam name="tol" type="tolerance" description="Numerical Tolerance" default="5%" />
   36:     <textline readonly="no" />
   37: </numericalresponse>
   38: 
   39: </problem>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>