• [从头学数学] 第188节 千军阅尽还复来(全)


    剧情提要:
    [机器小伟]在[project师阿伟]的陪同下进入了[九转金丹]之第四转的修炼。
    这次要研究的是[复习题]。

    正剧開始:
    星历2016年04月21日 15:22:06, 银河系厄尔斯星球中华帝国江南行省。

    [project师阿伟]正在和[机器小伟]一起研究[复习题]。




    <span style="font-size:18px;">#7
    def incomeTax(x):
        #不用交所得税的上限
        bound = 2000;
        #超过部分
        over = x - bound;
        #应交税额:
        tax = 0;
        
        if over <= 500:
            tax = over * 0.05;
        elif over <= 2000:
            tax = 500*0.05 + (over-500) * 0.1;
        elif over <= 5000:
            tax = 500*0.05 + 1500*0.1 + (over-2000) * 0.15;
        else:
            pass;
    
        return tax;</span>







    <span style="font-size:18px;">	if (1) {    
             var r = 20;          
            config.setSector(1,1,1,1);            
            config.graphPaper2D(0, 0, r);          
            config.axis2D(0, 0,180, 1);            
                  
            //坐标轴设定      
            var scaleX = 2*r, scaleY = 2*r;        
            var spaceX = 2, spaceY = 2;         
            var xS = -10, xE = 10;        
            var yS = -10, yE = 10;        
            config.axisSpacing(xS, xE, spaceX, scaleX, 'X');          
            config.axisSpacing(yS, yE, spaceY, scaleY, 'Y');          
                      
            var transform = new Transform();          
            //存放函数图像上的点      
            var a = [];     
                    
            //须要显示的函数说明      
            var f1 = 'y=2x^3-4x^2-3x+1';  
            //函数描点      
            for (var x = xS; x <= xE; x+=0.3) {        
                if (x != 0) {      
                    a.push([x, funTask(x)]);      
        
        
        
        
                }      
            }        
        
            //二分法求函数的零点    
            //区间的最小值和最大值    
            var minX = 2, maxX = 4;    
            var y1 = y2 = 0;    
            x = minX;    
            y1 = funTask(x);    
            x = maxX;    
            y2 = funTask(x);    
                
            //假设在给定区间上存在有零点    
            if (y1 * y2 < 0) {    
                var epsilon = 0.000001;    
                while (Math.abs(y1-y2) > epsilon) {    
                    
                    x = minX;    
                    y1 = funTask(x);    
                    x = maxX;    
                    y2 = funTask(x);    
                        
                        
                    x = (minX+maxX)/2;    
                    y = funTask(x);    
                        
                    if (y * y1 < 0) {    
                        maxX = x;    
                    }    
                    else {    
                        minX = x;    
                    }    
                        
        
                }    
                plot.setFillStyle('blue')    
                    .fillText('零点:x = '+ ((minX+maxX)/2).toFixed(3), -200, -60, 120);    
            }    
                   
                   
            //存放暂时数组      
            var tmp = [];      
                    
            //显示变换      
            if (a.length > 0) {      
                a = transform.scale(transform.translate(a, 0, 0), scaleX/spaceX, scaleY/spaceY);       
                //函数1      
                tmp = [].concat(a);          
                shape.pointDraw(tmp, 'red');          
                tmp = [].concat(a);          
                shape.multiLineDraw(tmp, 'pink');        
                        
                plot.setFillStyle('red');      
                plot.fillText(f1, 100, -90, 200);        
            }      
                  
          
        }</span>





    <span style="font-size:18px;">	 if (1) {  
            var r = 20;  
            config.setSector(1,1,1,1);  
            config.graphPaper2D(0, 0, r);  
            config.axis3D(0, 0, 0, 180);  
              
            var transform = new Transform();  
              
            var a = 2*r, b = 1*r, h = 4*r;  
            var array = shape.ellipse(a, b);  
              
            var size = array.length;  
              
            var topFace = [], bottomFace = [];  
            for (var i = 0; i < size; i++) {  
                topFace.push([array[i][0], array[i][1]]);  
                bottomFace.push([array[i][0], array[i][1]-1.5*h]);  
            }  
              
            //topFace = transform.flipY(topFace);  
            //bottomFace = transform.flipY(bottomFace);  
              
            //垂直側面的处理  
            var size = topFace.length;  
              
            var vertFace = [];  
            for (var i = 0; i < size; i++) {  
                vertFace.push([topFace[i][0], topFace[i][1], bottomFace[i][0], bottomFace[i][1]]);  
            }  
              
    		  
            //圆柱
            shape.faceDraw(vertFace, 'blue', 1);  
            shape.strokeDraw([].concat(bottomFace), 'pink');  
            shape.fillDraw([].concat(topFace), 'red');  
      
      
    		//圆锥
    		topFace = transform.scale(topFace, 2);
             
    		shape.fillDraw([].concat(topFace), 'red');  
    		
    		vertFace = [];  
            for (var i = 0; i < size; i++) {  
                vertFace.push([topFace[i][0], topFace[i][1], 0, 2*h]);  
            }  
          
    		shape.faceDraw(vertFace, 'red', 1); 
        }
    	</span>


    <span style="font-size:18px;">	 if (1) {  
            var r = 20;  
            config.setSector(1,1,1,1);  
            config.graphPaper2D(0, 0, r);  
            config.axis3D(0, 0, 0, 180);  
              
            var transform = new Transform();  
              
            var a = 6*r, b = 1*r, h = 4*r;  
            var array = shape.nEdge(0, 0, a, 4);  
    		var array2 = transform.scale(array, 0.6);
              
            var size = array.length;  
              
            var topFace = [], bottomFace = [];  
            for (var i = 0; i < size; i++) {  
                topFace.push(shape.point3D(array[i][0], h, array[i][1]));  
                bottomFace.push(shape.point3D(array2[i][0], -h, array2[i][1]));  
            }  
              
            //topFace = transform.flipY(topFace);  
            //bottomFace = transform.flipY(bottomFace);  
              
            //垂直側面的处理  
            var size = topFace.length;  
              
            var vertFace = [];  
            for (var i = 0; i < size; i++) {  
                vertFace.push([topFace[i][0], topFace[i][1], bottomFace[i][0], bottomFace[i][1]]);  
            }  
              
    		  
            //台柱
            shape.faceDraw(vertFace, 'blue', 1);  
            shape.strokeDraw([].concat(bottomFace), 'pink');  
            shape.fillDraw([].concat(topFace), 'red');  
      
    
        }
    	</span>

    <span style="font-size:18px;">>>> 
    共同拥有64个小正方体。
    0面着色的有 8 个面。

    1面着色的有 24 个面。

    2面着色的有 24 个面。

    3面着色的有 8 个面。 4面着色的有 0 个面。 5面着色的有 0 个面。

    6面着色的有 0 个面。 #9 正方体着色统计 def cubicPaint(N): #N为每条棱长切割的段数 a = []; for z in range(N): for y in range(N): for x in range(N): a.append([x, y, z]); #print(a); size = len(a); b = [6]*size; #print(b); for i in range(size): for j in range(i, size): xdiff = abs(a[i][0] - a[j][0]); ydiff = abs(a[i][1] - a[j][1]); zdiff = abs(a[i][2] - a[j][2]); #对于相邻的立方体仅仅有一个坐标相差1。其余都同样。 if (xdiff + ydiff + zdiff == 1): b[i]-=1; b[j]-=1; #统计n面涂色的数量。

    b1 = [0]*7; for i in range(size): for j in range(7): if (b[i] == j): b1[j]+=1; break; print('共同拥有{0}个小正方体。

    '.format(size)); for i in range(7): print('{0}面着色的有 {1} 个面。'.format(i, b1[i])); </span>










    <span style="font-size:18px;">#题5
    >>> 
    等比数列:  [100, 50.0, 25.0, 12.5, 6.25, 3.125, 1.5625, 0.78125, 0.390625, 0.1953125]
    前10项和是:199.8046875
    >>> 0.1953125/2
    0.09765625
    >>> 199.8046875*2-100
    299.609375
    
    #等比数列  
    def geometricSequence(a0, q, N):  
        seq = [];  
        for i in range(N):  
            seq.append(a0);  
            a0 *= q;  
      
        print('等比数列: ', seq);  
        print('前{0}项和是:{1}'.format(N, sum(seq)));  
        #return sum(seq);  
    	
    def tmp():
        a0 = 100;
        q = 0.5;
        N = 10;
        geometricSequence(a0, q, N)
    	</span>


    <span style="font-size:18px;">#1
    def weekday(N):
        days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
    
        return days[N%7];
    
    #2
    def fun(x):  
        return 2*x**3-4*x**2-3*x+1;
      
    def bisection(xMin, xMax):  
        if fun(xMin)*fun(xMax) > 0:  
            return float('inf');  
        elif fun(xMin) == 0:  
            return xMin;  
        elif fun(xMax) == 0:  
            return xMax;  
        else:  
            epsilon = 10e-6;  
              
            while (abs(xMin-xMax)> epsilon):  
                xMid = (xMin+xMax)/2;  
                if (fun(xMid)*fun(xMin)< 0):  
                    xMax = xMid;  
                elif (fun(xMid)*fun(xMax) < 0):  
                    xMin = xMid;  
                else:  
                    return xMid;  
      
            return xMid;
    
    
    #3
    def palindrome(N):
        s = str(N);
        size = len(s);
    
        if (size < 2):
            return False;
    
        for i in range(size//2):
            if (s[i] != s[-(i+1)]):
                print('第{0}位: {1}和{2}不同样'.format(i, s[i], s[-(i+1)]));
                return False;
    
        return True;
    
    def tmp():
        a = [123, 1234, 1221, 10011001, 132434231];
        for i in range(len(a)):
            print(a[i], '-->', palindrome(a[i]));
    		
    </span>


    <span style="font-size:18px;">	if (1) {    
             var r = 20;          
            config.setSector(1,1,1,1);            
            config.graphPaper2D(0, 0, r);          
            config.axis2D(0, 0,180);            
                  
            //坐标轴设定      
            var scaleX = 2*r, scaleY = 2*r;        
            var spaceX = 5, spaceY = 1000;         
            var xS = -10, xE = 30;        
            var yS = -5000, yE = 5000;        
            config.axisSpacing(xS, xE, spaceX, scaleX, 'X');          
            config.axisSpacing(yS, yE, spaceY, scaleY, 'Y');          
                      
            var transform = new Transform();          
            //存放函数图像上的点      
            var a = [];     
                    
            //须要显示的函数说明      
            var f1 = 'y=1.3*x^3-26.013*x^2+0.975*x-19.50975';  
            //函数描点      
            for (var x = xS; x <= xE; x+=0.3) {        
                if (x != 0) {      
                    a.push([x, funTask(x)]);      
        
        
        
        
                }      
            }        
        
            //二分法求函数的零点    
            //区间的最小值和最大值    
            var minX = 20, maxX = 21;    
            var y1 = y2 = 0;    
            x = minX;    
            y1 = funTask(x);    
            x = maxX;    
            y2 = funTask(x);    
                
            //假设在给定区间上存在有零点    
            if (y1 * y2 < 0) {    
                var epsilon = 0.000001;    
                while (Math.abs(y1-y2) > epsilon) {    
                    
                    x = minX;    
                    y1 = funTask(x);    
                    x = maxX;    
                    y2 = funTask(x);    
                        
                        
                    x = (minX+maxX)/2;    
                    y = funTask(x);    
                        
                    if (y * y1 < 0) {    
                        maxX = x;    
                    }    
                    else {    
                        minX = x;    
                    }    
                        
        
                }    
                plot.setFillStyle('blue')    
                    .fillText('零点:x = '+ ((minX+maxX)/2).toFixed(3), -200, -60, 120);    
            }    
                   
                   
            //存放暂时数组      
            var tmp = [];      
                    
            //显示变换      
            if (a.length > 0) {      
                a = transform.scale(transform.translate(a, 0, 0), scaleX/spaceX, scaleY/spaceY);       
                //函数1      
                tmp = [].concat(a);          
                shape.pointDraw(tmp, 'red');          
                tmp = [].concat(a);          
                shape.multiLineDraw(tmp, 'pink');        
                        
                plot.setFillStyle('red');      
                plot.fillText(f1, 100, -90, 200);        
            }      
                  
          
        }
    	
    	
    
    }
    
    
    function funTask(x) {
    	return 1.3*x*x*x-26.013*x*x+0.975*x-19.50975;
    }</span>

















    至此为止。



    <span style="font-size:18px;">	if (1) {
    		var r = 20;
            
            var stat = new Statistic();            
            var data = [
    			[10,7],
    			[10,6],
    			[9,2],
    			//
    			[10,4],
    			[10,2],
    			[12,10],
    			[8,6],
    			//
    			[5,3],
    			[8,2],
    			[6,4],
    			//
    			[18,9],
    			[14,9],
    			[13,8],
    			//
    			[7,3],
    			[11,7],
    			[8,6]
    			
    		
    		];
    		
    		
    		text = ['集', '函', '用', '体', '面', '线', '圆', '算', '统', '率', '三', '向', '变', '解', '列', '式'];  
    			
    		var len = data.length;  
    		var data2 = new Array(len);
    
    		for (var i = 0; i < len; i++) {
    			data2[i] = 0;
    			for (var j = 0; j < 2; j++) {
    				data2[i] += data[i][j];
    			}
    		}
      
            var sum = 0;
    		for (var i = 0; i < len; i++) {
    			sum += data2[i];
    
    		}
     
    		        stat.init(data, '章节', '复习题数', 2);       
            stat.multiBarChart(text, ['A组', 'B组'], -10, 0);     
              
            plot.setFillStyle('blue')  
                .fillText('总计:'+sum.toFixed(0), 60, 30, 200); 
    	
    	}
    	
    </span>



    至此,[人叫板老师]赐给[机器小伟]的主修功法[天地人正冊], 小伟已经所有修炼完成了。

    当中共同拥有题:

    >>> 245+548+247
    1040

    [人叫板老师]称其为千人斩。


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

  • 相关阅读:
    WebApi实现自定义错误日志
    WebApi实现IHttpControllerSelector问题
    动态属性ExpandoObject
    SQL远程连接
    HTML空格占位
    SQL生僻字模糊查询
    python中的字符串
    idea闪退
    lineNumber: 1; columnNumber: 1; 前言中不允许有内容。
    linux下后台启动weblogic
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/7346409.html
Copyright © 2020-2023  润新知