Annotation of loncom/homework/templates/Plot_data.problem, revision 1.4.8.1
1.1 matthew 1: <problem>
2:
3: <script type="loncapa/perl">
1.4.8.1 ! raeburn 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: #
1.4 www 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));
1.4.8.1 ! raeburn 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; }
1.4 www 17: }
1.1 matthew 18: </script>
19:
1.3 albertel 20: <gnuplot width="300" transparent="off" samples="100" grid="on" font="9" bgcolor="xffffff" height="300" align="left" fgcolor="x000000" border="on" plottype="Cartesian" >
1.4 www 21: <axis xmin="$x_min" ymin="-5" xmax="$x_max" ymax="5" color="x000000" />
1.1 matthew 22: <xlabel>Label X</xlabel>
23: <ylabel>Label Y</ylabel>
24: <curve linestyle="linespoints" name="My Plot" pointtype="0" color="x000000">
1.4 www 25: <data>@X</data>
26: <data>@Y</data>
1.1 matthew 27: </curve>
28: </gnuplot>
29:
1.4 www 30: <startouttext />What is the amplitude of this function?<endouttext />
1.1 matthew 31:
1.4 www 32: <numericalresponse answer="$amplitude" format="2s">
1.1 matthew 33: <responseparam name="tol" type="tolerance" description="Numerical Tolerance" default="5%" />
1.4 www 34:
35: <textline readonly="no" />
36:
1.1 matthew 37: </numericalresponse>
38: </problem>
39:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>