File:  [LON-CAPA] / loncom / homework / templates / Plot_data.problem
Revision 1.4.8.1: download - view: text, annotated - select for diffs
Fri Aug 20 03:54:56 2010 UTC (13 years, 8 months ago) by raeburn
Branches: version_2_9_X
CVS tags: version_2_9_1
Diff to branchpoint 1.4: preferred, colored
- Backport 1.6.

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

<gnuplot width="300" transparent="off" samples="100" grid="on" font="9" bgcolor="xffffff" height="300" align="left" fgcolor="x000000" border="on" plottype="Cartesian" >
    <axis xmin="$x_min" ymin="-5" xmax="$x_max" ymax="5" color="x000000" />
    <xlabel>Label X</xlabel>
    <ylabel>Label Y</ylabel>
    <curve linestyle="linespoints" name="My Plot" pointtype="0" color="x000000">
        <data>@X</data>
        <data>@Y</data>
    </curve>
</gnuplot>

<startouttext />What is the amplitude of this function?<endouttext />

<numericalresponse answer="$amplitude" format="2s">
    <responseparam name="tol" type="tolerance" description="Numerical Tolerance" default="5%" />
    
    <textline readonly="no" />

</numericalresponse>
</problem>


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