[从头学数学] 第108节 有理数

来源:互联网 发布:局域网聊天软件排行 编辑:程序博客网 时间:2024/04/28 08:37
剧情提要:
[机器小伟]在[工程师阿伟]的陪同下进入了筑基初期的修炼,
这次要修炼的目标是[整理与复习--综合与实践]。

正剧开始:

星历2016年02月25日 10:20:16, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]一起研究有理数。


经过漫长的修炼,以及对筑基丹的炼化,[机器小伟]成功地进入了筑基期。

从现在开始,[人叫板老师]给[机器小伟]的功法也少了很多的图,而多了

很多的文字。不过,这对于[机器小伟]来说,又算得了什么呢。


现在,小伟正翻看着[人叫板老师]给的新功法:


接下来就要修炼第一部分了:


虽然[人叫板老师]的图少了,但小伟的图是不会少的,毕竟,小伟的格言就是有图有真相,没图没啥说。


[人叫板老师]依然用对金钱的认识引导着小伟进入对有理数的认识。





然后[人叫板老师]郑重地告诉小伟什么是有理数:


好吧,老师说啥就是啥,反正小伟无所谓。

接着,小伟看到了数轴:


小伟觉得怎么着也要设计一个数轴来用一用了:

<span style="font-size:18px;">/*** @usage   数轴* @author  mw* @date    2016年02月25日  星期四  09:17:23 * @param* @return**/this.axis1D = function(xOff, yOff, r) {plot.save();yOff = -yOff;plot.setFillStyle('black').setStrokeStyle('black');plot.beginPath().moveTo(xOff-r,0).lineTo(xOff+r,0).closePath().stroke();var r0 = 10;//x轴箭头plot.beginPath().moveTo(xOff+r- r0*Math.cos(Math.PI/3), yOff-r0*Math.sin(Math.PI/3)).lineTo(xOff+r+r0*Math.sin(Math.PI/3), yOff).lineTo(xOff+r -r0*Math.cos(Math.PI/3), yOff+r0*Math.sin(Math.PI/3)).closePath().fill()plot.fillText("X", xOff+r, yOff-10, 20);var pxPerCm = (r-10)/10;var cm10th =pxPerCm / 10;var cm5th = pxPerCm / 5;var cm2th = pxPerCm / 2;//数轴表示从-10到10var x=xOff-r+10, y=0, count = -10;var L = pxPerCm * 10;//cm刻度plot.setStrokeStyle('red');while (x <= L+10) {if (count == 0) {plot.beginPath().moveTo(x, 0).lineTo(x, -cm5th*5).closePath().stroke();}else if (Math.abs(count)%5 == 0) {plot.beginPath().moveTo(x, 0).lineTo(x, -cm5th*3).closePath().stroke();}else {plot.beginPath().moveTo(x, 0).lineTo(x, -cm5th*2).closePath().stroke();}if (Math.abs(count)%5 == 0) {if (count < 10) {plot.fillText(count.toFixed(0), x-2*cm10th, 2 * cm2th, 20);}else {plot.fillText(count.toFixed(0), x-2*cm5th, 2 * cm2th, 20);}}x += pxPerCm;count++;}/*//半厘米刻度x=0, y=0, count = 0;plot.setStrokeStyle('#CC0000');while (x <= L) {if (count % 2 != 0) {plot.beginPath().moveTo(x, 0).lineTo(x, cm5th).closePath().stroke();}x += cm2th;count++;}//0.1cm刻度plot.setStrokeStyle('#880000');x=0, y=0, count = 0;while (x <= L) {if (count % 10 != 0 && count % 10 != 5) {plot.beginPath().moveTo(x, 0).lineTo(x, cm10th).closePath().stroke();}x += cm10th;count++;}*/plot.restore();}function myDraw() {     var config = new PlotConfiguration();        config.init();        config.setPreference();   config.setSector(1,1,1,1);config.axis1D(0, 0, 180);}</span>

这个数轴的效果是这样的:


先来做个测试吧:

<span style="font-size:18px;">function myDraw() {     var config = new PlotConfiguration();        config.init();        config.setPreference();   config.setSector(1,1,1,1);config.axis1D(0, 0, 180);var r = 180-10;//刻度 scale; graduation ; var scale = r / 10;var array = [3.5,8.5,-4.5,4.0,-5.2,-1.2];var size = array.length;array.sort(function(a, b) { return a-b;});plot.fillText(array.join('    '), -100, 50, 400);//存放点阵列var points = [];for (var i = 0; i < size; i++) {points.push([array[i]*scale, 0]);}//由于shape采用的是弹出数据的方式,所以拷贝一个副本来进行操作var tmp = points;shape.pointDraw(tmp, 'green');}</span>



再来对照一下例题:

<span style="font-size:18px;">function myDraw() {     var config = new PlotConfiguration();        config.init();        config.setPreference();   config.setSector(1,1,1,1);config.axis1D(0, 0, 180);var r = 180-10;//刻度 scale; graduation ; var scale = r / 10;var array = [3, 7.5, 0, -3, -4.8];var size = array.length;array.sort(function(a, b) { return a-b;});//plot.fillText(array.join('    '), -100, 50, 400);//存放点阵列var points = [];for (var i = 0; i < size; i++) {points.push([array[i]*scale, 0]);}//由于shape采用的是弹出数据的方式,所以拷贝一个副本来进行操作var tmp = points;shape.pointDraw(tmp, 'green');for (var i = 0; i < size; i++) {plot.fillText(array[i].toString(), array[i]*scale-10, 20, 50);}}</span>






<span style="font-size:18px;">function myDraw() {     var config = new PlotConfiguration();        config.init();        config.setPreference();   config.setSector(1,1,1,1);config.axis1D(0, 0, 180);var r = 180-10;//刻度 scale; graduation ; var scale = r / 10;var array = [-5, -2, 2, 5];var size = array.length;array.sort(function(a, b) { return a-b;});//plot.fillText(array.join('    '), -100, 50, 400);//存放点阵列var points = [];for (var i = 0; i < size; i++) {points.push([array[i]*scale, 0]);}//由于shape采用的是弹出数据的方式,所以拷贝一个副本来进行操作var tmp = points;shape.pointDraw(tmp, 'green');for (var i = 0; i < size; i++) {plot.fillText(array[i].toString(), array[i]*scale-10, 20, 50);}}</span>


到这里,[人叫板老师]觉得概念介绍差不多了,下面要进入四则运算了。


<span style="font-size:18px;">#例1(-3)+(-9) = -12, (-4.7)+3.9 = -4/5 = -0.8 = -80%, </span>


<span style="font-size:18px;">#例391+91+91.5+89+91.2+91.3+88.7+88.8+91.8+91.1 = 4527/5 = 905.4, 1+1+1.5+(-1)+1.2+1.3+(-1.3)+(-1.2)+1.8+1.1 = 27/5 = 5.4 = 540%, </span>


这个幻方,就是九宫中的数都减去5,位置是一模一样的。



<span style="font-size:18px;">#例4(-3)-(-5) = 2 = 200%, 0-7 = -7 = -700%, 7.2-(-4.8) = 12, (-7/2)-5-1/4 = -35/4 = -8.75 = -875%, </span>



<span style="font-size:18px;">#例1(-3)*9 = -27, 8*(-1) = -8 = -800%, (-1/2)*(-2) = 1 = 100%, </span>


<span style="font-size:18px;">#例3(-3)*5/6*(-9/5)*(-1/4) = -9/8 = -1.125 = -112.5%, (-5)*6*(-4/5)*1/4 = 6 = 600%, </span>


<span style="font-size:18px;">#例5(-36)/9 = -4 = -400%, (-12/25)/(-3/5) = 4/5 = 0.8 = 80%, </span>


<span style="font-size:18px;">#例7(-125-5/7)/(-5) = 176/7 = 25.143, -2.5/(5/8)*(-1/4) = 1 = 100%, </span>


[人叫板老师]又提出了乘方的概念,从此,要多一种数学运算了。



<span style="font-size:18px;">#例1(-4)**3 = -64, (-2)**4 = 16, (-2/3)**3 = -8/27 = -0.296 = -29.63%, </span>


<span style="font-size:18px;">#例2(-8)**5 = -32768, (-3)**6 = 729, </span>

有[机器小伟]在,还用得着计算器吗?


<span style="font-size:18px;">#例32*(-3)**3-4*(-3)+15 = -27, (-2)**3+(-3)*((-4)**2+2)-(-3)**2/(-2) = -115/2 = -57.5, </span>




<span style="font-size:18px;">>>> 1e+065.7e+07-1.23e+11#科学计数法def tmp():    print('{0:.0e}'.format(1000000));    print('{0:.1e}'.format(57000000));    print('{0:.2e}'.format(-123000000000));</span>



>>> 0.0163041.81.80


#近似数

<span style="font-size:18px;">def tmp(num, accuracy):    if accuracy > 0:        result = str(round(num, accuracy));    else:        result = str(round(num));    #对于要求保留小数的情况,由于一般末尾的0会被舍弃,    #导致精度位数不够,所以在此进行判断补充。    if accuracy > 0:        pos = result.find('.');        diff = accuracy-(len(result)-pos-1);        result += '0'*diff;    print(result);    if __name__ == '__main__':    tmp(0.0158, 3);    tmp(304.35, 0);    tmp(1.804, 1);    tmp(1.804, 2);</span>

本节中多处与例题进行对比计算,是为了测试小伟的计算工具是否有效,是否会出错,

通过对比可知一般来说,可以保证正确度,对于算式中有四则运算以外的比如乘方这种运算,

小伟也不能完全保证不会出错,但应该也不会错太多。这个工具在下一节的复习中贴出,

这里就不贴了。

本节到此结束,欲知后事如何,请看下回分解。

1 0
原创粉丝点击