File:
[LON-CAPA] /
loncom /
html /
adm /
help /
tex /
Authoring_Piecewise_Plot.tex
Revision
1.2:
download - view:
text,
annotated -
select for diffs
Wed Dec 11 19:04:47 2002 UTC (21 years, 8 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_X,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
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,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_X,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
version_1_1_3,
version_1_1_2,
version_1_1_1,
version_1_1_0,
version_1_0_99_3,
version_1_0_99_2,
version_1_0_99_1,
version_1_0_99,
version_1_0_3,
version_1_0_2,
version_1_0_1,
version_1_0_0,
version_0_99_5,
version_0_99_4,
version_0_99_3,
version_0_99_2,
version_0_99_1,
version_0_99_0,
version_0_6_2,
version_0_6,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
conference_2003,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse
- spellchecked (BUG#1052)
1: \label{Authoring_Piecewise_Plot}
2: Suppose you want to plot a piecewise function similar to the
3: following:
4:
5: \begin{verbatim}
6: f(x) = a*x + b if (x < 4.5)
7: f(x) = a*x if (x >=4.5)
8: \end{verbatim}
9:
10: The following is the XML representation of a problem with a dynamic
11: plot based on this. The work is done in a <script> block that
12: generates the data sets used in the plot.
13:
14: \begin{verbatim}
15: <script type="loncapa/perl" >
16: $a = &random(2,5,1);
17: $b = &random(3,6,1);
18:
19: for ($x = 0; $x<4.5; $x+= 0.05) {
20: push @X, $x;
21: push @Y, $a*$x + $b;
22: }
23:
24: for ($x = 4.5; $x<=10; $x+= 0.05) {
25: push @X, $x;
26: push @Y, $a*$x;
27: }
28: </script >
29: <gnuplot font="medium" width="500" grid="on" height="400" border="on"
30: fgcolor="x000000" alttag="dynamically generated plot" align="center"
31: bgcolor="xffffff" transparent="off" >
32: <curve linestyle="lines" pointsize="1" pointtype="1" color="x000000"
33: name="">
34: <data >@X</data >
35: <data >@Y</data >
36: </curve >
37: </gnuplot >
38: \end{verbatim}
39:
40: The above script works, but it produces a plot like this:
41:
42: \includegraphics{dynamic_piecewise}
43:
44: A better solution is to use two separate <curve> statements to plot
45: two separate curves. So on the second piece of the function we use
46: @X2 and @Y2 instead of @X and @Y. Then in the <gnuplot> tag we
47: include a second <curve> sub-tag.
48:
49: \begin{verbatim}
50: <script type="loncapa/perl" >
51: $a = &random(2,5,1);
52: $b = &random(3,6,1);
53:
54: for ($x = 0; $x<4.5; $x+= 0.05) {
55: push @X, $x;
56: push @Y, $a*$x + $b;
57: }
58:
59: for ($x = 4.5; $x<=10; $x+= 0.05) {
60: push @X2, $x;
61: push @Y2, $a*$x;
62: }
63: </script >
64: <gnuplot font="medium" width="500" grid="on" height="400" border="on"
65: fgcolor="x000000" alttag="dynamically generated plot" align="center"
66: bgcolor="xffffff" transparent="off" >
67: <curve linestyle="lines" pointsize="1" pointtype="1" color="x000000"
68: name="" >
69: <data >@X</data >
70: <data >@Y</data >
71: </curve >
72: <curve linestyle="lines" pointsize="1" pointtype="1" color="x000000"
73: name="" >
74: <data >@X2</data >
75: <data >@Y2</data >
76: </curve >
77: </gnuplot >
78: \end{verbatim}
79:
80: \includegraphics{dynamic_piecewise2}
81:
82: This is still not a desirable result. Typically one wants an open
83: circle or closed circle defining the domain of each
84: piece. Unfortunately there is no easy way to do this in gnuplot
85: currently. If this effect is desired, perhaps using a static image
86: and a randomlabel problem would be a better approach. A second
87: solution would be to add data which draws a circle to your curves.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>