自适应调整分割数的积分演示
2015-10-12 07:14
本范例演示了如何通过自适应调整分割数来计算定积分。利用JavaScript和GeoGebra命令,动态生成黎曼和(梯形法),并实时计算积分近似值与真实值的误差百分比。用户可通过输入框调整参数,直观观察分割数增加时积分精度的提升过程,深入理解微积分中黎曼和与定积分的逼近关系。
所属专题
微积分
GeoGebra 画板及绘图内容加载中,请稍等……
<?xml version="1.0" encoding="utf-8"?>
<geogebra format="5.0" version="5.0.156.0" id="b54bae83-e62a-4c03-a86d-d36f709a9329" xsi:noNamespaceSchemaLocation="http://www.geogebra.org/ggb.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<gui>
<window width="800" height="600" />
<perspectives>
<perspective id="tmp">
<panes>
<pane location="" divider="0.2575" orientation="1" />
</panes>
<views>
<view id="4097" visible="false" inframe="true" stylebar="true" location="1,1,1,1" size="400" window="735,231,835,719" />
<view id="4" toolbar="0 || 2020 , 2021 , 2022 , 66 || 2001 , 2003 , 2002 , 2004 , 2005 || 2040 , 2041 , 2042 , 2044 , 2043" visible="false" inframe="false" stylebar="false" location="1,1" size="300" window="100,100,600,400" />
<view id="8" toolbar="1001 | 1002 | 1003 || 1005 | 1004 || 1006 | 1007 | 1010 || 1008 1009 || 66 68 || 6" visible="false" inframe="false" stylebar="false" location="1,3" size="300" window="100,100,600,400" />
<view id="1" visible="true" inframe="false" stylebar="true" location="1" size="789" window="100,100,600,400" />
<view id="2" visible="false" inframe="true" stylebar="true" location="3" size="206" window="811,1,586,400" />
<view id="16" visible="false" inframe="false" stylebar="false" location="1" size="150" window="50,50,500,500" />
<view id="32" visible="false" inframe="false" stylebar="true" location="1" size="150" window="50,50,500,500" />
<view id="64" toolbar="0" visible="false" inframe="true" stylebar="true" location="1" size="150" window="50,50,500,500" />
<view id="70" toolbar="0 || 2020 || 2021 || 2022" visible="false" inframe="true" stylebar="true" location="1" size="150" window="50,50,500,500" />
<view id="512" toolbar="0 | 1 501 5 19 , 67 | 2 15 45 18 , 7 37 | 514 3 9 , 13 44 , 47 | 16 | 551 550 11 , 20 22 21 23 , 55 56 57 , 12 | 69 | 510 511 , 512 513 | 533 531 , 534 532 , 522 523 , 537 536 , 535 | 521 520 | 36 , 38 49 560 | 571 30 29 570 31 33 | 17 | 540 40 41 42 , 27 28 35 , 6 , 502" visible="false" inframe="false" stylebar="false" location="1" size="300" window="50,50,500,500" />
</views>
<toolbar show="true" items="0 39 | 1 501 67 , 5 19 , 72 | 2 15 45 , 18 65 , 7 37 | 4 3 8 9 , 13 44 , 58 , 47 | 16 51 64 , 70 | 10 34 53 11 , 24 20 22 , 21 23 | 55 56 57 , 12 | 36 46 , 38 49 50 , 71 | 30 29 54 32 31 33 | 17 26 62 73 , 14 68 | 25 52 60 61 | 40 41 42 , 27 28 35 , 6" position="1" help="true" />
<input show="true" cmd="true" top="false" />
<dockBar show="true" east="true" />
</perspective>
</perspectives>
<labelingStyle val="3"/>
<font size="12"/>
<graphicsSettings javaLatexFonts="false"/>
</gui>
<euclidianView>
<viewNumber viewNo="1"/>
<size width="789" height="467"/>
<coordSystem xZero="328.0" yZero="221.00000000000009" scale="49.99999999999998" yscale="50.00000000000002"/>
<evSettings axes="true" grid="false" gridIsBold="false" pointCapturing="3" rightAngleStyle="1" checkboxSize="26" gridType="0"/>
<bgColor r="255" g="255" b="255"/>
<axesColor r="0" g="0" b="0"/>
<gridColor r="192" g="192" b="192"/>
<lineStyle axes="1" grid="10"/>
<axis id="0" show="true" label="" unitLabel="" tickStyle="1" showNumbers="true"/>
<axis id="1" show="false" label="" unitLabel="" tickStyle="1" showNumbers="true"/>
</euclidianView>
<kernel>
<continuous val="false"/>
<usePathAndRegionParameters val="true"/>
<decimals val="2"/>
<angleUnit val="degree"/>
<algebraStyle val="0"/>
<coordStyle val="0"/>
<angleFromInvTrig val="false"/>
</kernel>
<scripting blocked="false" disabled="false"/>
<construction title="" author="" date="">
<command name="Point">
<input a0="xAxis"/>
<output a0="A"/>
</command>
<element type="point" label="A">
<show object="true" label="false" ev="4"/>
<objColor r="125" g="125" b="255" alpha="0.0"/>
<layer val="0"/>
<labelMode val="0"/>
<animation step="0.1" speed="1" type="1" playing="false"/>
<coords x="-3.0" y="0.0" z="1.0"/>
<pointSize val="5"/>
<pointStyle val="0"/>
</element>
<command name="Point">
<input a0="xAxis"/>
<output a0="B"/>
</command>
<element type="point" label="B">
<show object="true" label="false" ev="4"/>
<objColor r="125" g="125" b="255" alpha="0.0"/>
<layer val="0"/>
<labelMode val="0"/>
<animation step="1" speed="1" type="1" playing="false"/>
<coords x="5.0" y="0.0" z="1.0"/>
<pointSize val="5"/>
<pointStyle val="0"/>
</element>
<command name="Min">
<input a0="x(A)" a1="x(B)"/>
<output a0="a"/>
</command>
<element type="numeric" label="a">
<value val="-3.0"/>
<objColor r="0" g="0" b="0" alpha="0.1"/>
</element>
<command name="Max">
<input a0="x(A)" a1="x(B)"/>
<output a0="b"/>
</command>
<element type="numeric" label="b">
<value val="5.0"/>
<objColor r="0" g="0" b="0" alpha="0.1"/>
</element>
<expression label="s" exp="{a + (0 * b), (0.9 * a) + (0.09999999999999998 * b), (0.8 * a) + (0.2 * b), (0.7 * a) + (0.30000000000000004 * b), (0.6 * a) + (0.4 * b), (0.5 * a) + (0.5 * b), (0.3999999999999999 * a) + (0.6000000000000001 * b), (0.19999999999999996 * a) + (0.8 * b), (0.09999999999999998 * a) + (0.9 * b), (0 * a) + b}" />
<element type="list" label="s">
<objColor r="0" g="100" b="0" alpha="0.1"/>
<lineStyle thickness="2" type="0" typeHidden="1"/>
<pointSize val="3"/>
<pointStyle val="-1"/>
</element>
<command name="Length">
<input a0="s"/>
<output a0="m"/>
</command>
<element type="numeric" label="m">
<value val="10.0"/>
<objColor r="0" g="0" b="0" alpha="0.1"/>
</element>
<expression label ="f" exp="f(x) = sin(x) + x / 2"/>
<element type="function" label="f">
<show object="true" label="false" ev="4"/>
<objColor r="255" g="0" b="0" alpha="0.0"/>
<layer val="0"/>
<labelMode val="0"/>
<animation step="0.1" speed="1" type="0" playing="false"/>
<selectionAllowed val="false"/>
<lineStyle thickness="2" type="0" typeHidden="1"/>
</element>
<expression label="trap" exp="trap(p, q) = ((f(p) + f(q)) * (q - p) / 2)" />
<element type="functionNVar" label="trap">
<show object="true" label="false" ev="4"/>
<objColor r="255" g="0" b="0" alpha="0.75"/>
<layer val="0"/>
<labelMode val="0"/>
</element>
<command name="Sequence">
<input a0="trap(Element[s, k], Element[s, k + 1])" a1="k" a2="1" a3="m - 1"/>
<output a0="trapsArea"/>
</command>
<element type="list" label="trapsArea">
<objColor r="0" g="100" b="0" alpha="0.1"/>
<lineStyle thickness="2" type="0" typeHidden="1"/>
<pointSize val="3"/>
<pointStyle val="-1"/>
</element>
<command name="Integral">
<input a0="f" a1="a" a2="b"/>
<output a0="ans"/>
</command>
<element type="numeric" label="ans">
<value val="2.726345317936328"/>
<show object="false" label="true"/>
<objColor r="153" g="51" b="0" alpha="0.1"/>
<layer val="0"/>
<labelMode val="1"/>
<lineStyle thickness="2" type="0" typeHidden="1"/>
</element>
<element type="numeric" label="n">
<value val="5.0"/>
<show object="true" label="true"/>
<objColor r="153" g="102" b="255" alpha="0.1"/>
<layer val="0"/>
<labelOffset x="-56" y="-4"/>
<labelMode val="3"/>
<slider min="1" max="10" absoluteScreenLocation="true" width="100.0" x="597.0" y="422.0" fixed="false" horizontal="true"/>
<lineStyle thickness="10" type="0" typeHidden="1"/>
<animation step="1" speed="1" type="0" playing="false"/>
<caption val="初始分割數 = %v"/>
</element>
<command name="Sequence">
<input a0="Polygon[(Element[s, k], 0), (Element[s, k + 1], 0), (Element[s, k + 1], f(Element[s, k + 1])), (Element[s, k], f(Element[s, k]))]" a1="k" a2="1" a3="m - 1"/>
<output a0="area"/>
</command>
<element type="list" label="area">
<show object="true" label="false" ev="4"/>
<objColor r="0" g="100" b="0" alpha="0.1"/>
<layer val="0"/>
<labelMode val="0"/>
<selectionAllowed val="false"/>
<lineStyle thickness="2" type="0" typeHidden="1"/>
<pointSize val="3"/>
<pointStyle val="-1"/>
</element>
<element type="numeric" label="x0">
<value val="5.0"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0.1"/>
<layer val="0"/>
<labelMode val="1"/>
<animation step="1" speed="1" type="0" playing="false"/>
</element>
<expression label="y0" exp="f(x0)" />
<element type="numeric" label="y0">
<value val="1.5410757253368614"/>
<objColor r="0" g="0" b="0" alpha="0.1"/>
</element>
<element type="button" label="button1">
<show object="true" label="true"/>
<objColor r="255" g="153" b="204" alpha="1.0"/>
<bgColor r="255" g="192" b="203" alpha="255"/>
<layer val="0"/>
<labelOffset x="274" y="405"/>
<labelMode val="0"/>
<animation step="1" speed="1" type="0" playing="false"/>
<auxiliary val="true"/>
<javascript val="var x1 = ggbApplet.getValue('a'); var x2 = ggbApplet.getValue('b'); var n = ggbApplet.getValue('n'); var err = ggbApplet.getValue('err'); integrateAdaptiveMidpoint(f, x1, x2, n, err);"/>
<font serif="false" sizeM="2.0" size="12" style="0"/>
<file name="/geogebra/main/nav_play.png"/>
</element>
<command name="Sum">
<input a0="area"/>
<output a0="areaAdaptive"/>
</command>
<element type="numeric" label="areaAdaptive">
<value val="10.877633183658245"/>
<objColor r="0" g="0" b="0" alpha="0.1"/>
</element>
<command name="Textfield">
<input a0="f"/>
<output a0="inputBox1"/>
</command>
<element type="textfield" label="inputBox1">
<show object="true" label="true"/>
<objColor r="0" g="0" b="0" alpha="0.0"/>
<layer val="0"/>
<labelOffset x="36" y="406"/>
<labelMode val="0"/>
<animation step="1" speed="1" type="0" playing="false"/>
<fixed val="true"/>
<auxiliary val="true"/>
<linkedGeo exp="f"/>
<caption val="f(x)="/>
</element>
<element type="numeric" label="err">
<value val="0.05"/>
<show object="true" label="true"/>
<objColor r="255" g="102" b="153" alpha="0.1"/>
<layer val="0"/>
<labelOffset x="-23" y="-3"/>
<labelMode val="3"/>
<slider min="0.01" max="1" absoluteScreenLocation="true" width="100.0" x="378.0" y="421.0" fixed="false" horizontal="true"/>
<lineStyle thickness="10" type="0" typeHidden="1"/>
<animation step="0.01" speed="1" type="0" playing="false"/>
<caption val="誤差 = %v"/>
</element>
<expression label="text2" exp=""積分面積:" + ans + """ />
<element type="text" label="text2">
<show object="true" label="false" ev="40"/>
<objColor r="0" g="0" b="0" alpha="0.0"/>
<layer val="0"/>
<labelMode val="0"/>
<startPoint x="-5.720000000000006" y="2.9000000000000004" z="1.0"/>
</element>
<expression label="errPercent" exp="(abs((Sum[trapsArea] - ans) / ans) * 100)" />
<element type="numeric" label="errPercent">
<value val="2.069233388878543"/>
<objColor r="0" g="0" b="0" alpha="0.1"/>
</element>
<expression label="text3" exp=""實際誤差:" + errPercent + " %"" />
<element type="text" label="text3">
<show object="true" label="false" ev="40"/>
<objColor r="255" g="0" b="0" alpha="0.0"/>
<layer val="0"/>
<labelMode val="0"/>
<decimals val="2"/>
<startPoint x="-5.720000000000003" y="2.4000000000000004" z="1.0"/>
</element>
<expression label="text1" exp=""梯形面積:" + (Sum[trapsArea]) + """ />
<element type="text" label="text1">
<show object="true" label="false" ev="8"/>
<objColor r="0" g="0" b="0" alpha="0.0"/>
<layer val="0"/>
<labelMode val="0"/>
<startPoint x="-5.700000000000003" y="3.4" z="1.0"/>
</element>
<expression label="text4" exp=""梯形個數:" + (m - 1) + """ />
<element type="text" label="text4">
<show object="true" label="false" ev="40"/>
<objColor r="0" g="100" b="0" alpha="0.0"/>
<layer val="0"/>
<labelMode val="0"/>
<startPoint x="-5.720000000000004" y="1.940000000000001" z="1.0"/>
</element>
</construction>
</geogebra>