2017年6月29日木曜日

学習環境

解析入門〈2〉(松坂 和夫(著)、岩波書店)の第7章(積分法)、7.3(不定積分、広義積分)、問題3.を取り組んでみる。


  1. lim n ( i=1 n i α ) β+1 ( i=1 n i β ) α+1 = lim n n β+1+α( β+1 ) ( 1 n i=1 n ( i n ) α ) β+1 n α+1+β( α+1 ) ( 1 n i=1 n ( i n ) β ) α+1 = lim n ( 1 n i=1 n ( 0+ i( 10 ) n ) α ) β+1 ( 1 n i=1 n ( 0+ i( 10 ) n ) β ) α+1 = ( 0 1 x α dx ) β+1 ( 0 1 x β dx ) α+1 = ( [ 1 α+1 x α+1 ] 0 1 ) β+1 ( [ 1 β+1 x β+1 ] 0 1 ) α+1 = 1 ( α+1 ) β+1 1 ( β+1 ) α+1 = ( β+1 ) α+1 ( α+1 ) β+1

コード(Emacs)

Python 3

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sympy import pprint, symbols, summation, Limit, S, Pow
import random

i, n = symbols('i n', integer=True)
a, b = symbols('a b', positive=True)

pprint(summation(Pow(i, n), (i, 1, n)))
for _ in range(10):
    a0 = random.randrange(1, 11)
    b0 = random.randrange(1, 11)
    print('a = {0}, b = {1}'.format(a0, b0))
    f = Pow(summation(Pow(i, a), (i, 1, n)), (b + 1)) / \
        Pow(summation(Pow(i, b), (i, 1, n)), (a + 1))
    l = Limit(f.subs({a: a0, b: b0}), n, S.Infinity)
    pprint(l)
    result1 = l.doit()
    result2 = Pow(b0 + 1, a0 + 1) / Pow(a0 + 1, b0 + 1)
    pprint(result1)
    pprint(result2)
    print(result1 == result2)
    print()

入出力結果(Terminal, IPython)

$ ./sample3.py
  n     
 ___    
 ╲      
  ╲    n
  ╱   i 
 ╱      
 ‾‾‾    
i = 1   
a = 5, b = 2
              3
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    5⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
lim ───────────
n─→∞          6
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    2⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
27/8
27/8
True

a = 6, b = 5
              6
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    6⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
lim ───────────
n─→∞          7
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    5⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
279936
──────
117649
279936
──────
117649
True

a = 6, b = 9
              10
    ⎛  n     ⎞  
    ⎜ ___    ⎟  
    ⎜ ╲      ⎟  
    ⎜  ╲    6⎟  
    ⎜  ╱   i ⎟  
    ⎜ ╱      ⎟  
    ⎜ ‾‾‾    ⎟  
    ⎝i = 1   ⎠  
lim ────────────
n─→∞          7 
    ⎛  n     ⎞  
    ⎜ ___    ⎟  
    ⎜ ╲      ⎟  
    ⎜  ╲    9⎟  
    ⎜  ╱   i ⎟  
    ⎜ ╱      ⎟  
    ⎜ ‾‾‾    ⎟  
    ⎝i = 1   ⎠  
 10000000
─────────
282475249
 10000000
─────────
282475249
True

a = 4, b = 8
              9
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    4⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
lim ───────────
n─→∞          5
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    8⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
 59049 
───────
1953125
 59049 
───────
1953125
True

a = 7, b = 9
              10
    ⎛  n     ⎞  
    ⎜ ___    ⎟  
    ⎜ ╲      ⎟  
    ⎜  ╲    7⎟  
    ⎜  ╱   i ⎟  
    ⎜ ╱      ⎟  
    ⎜ ‾‾‾    ⎟  
    ⎝i = 1   ⎠  
lim ────────────
n─→∞          8 
    ⎛  n     ⎞  
    ⎜ ___    ⎟  
    ⎜ ╲      ⎟  
    ⎜  ╲    9⎟  
    ⎜  ╱   i ⎟  
    ⎜ ╱      ⎟  
    ⎜ ‾‾‾    ⎟  
    ⎝i = 1   ⎠  
 390625
───────
4194304
 390625
───────
4194304
True

a = 7, b = 5
              6
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    7⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
lim ───────────
n─→∞          8
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    5⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
6561
────
1024
6561
────
1024
True

a = 4, b = 1
              2
    ⎛  n     ⎞ 
    ⎜ ___    ⎟ 
    ⎜ ╲      ⎟ 
    ⎜  ╲    4⎟ 
    ⎜  ╱   i ⎟ 
    ⎜ ╱      ⎟ 
    ⎜ ‾‾‾    ⎟ 
    ⎝i = 1   ⎠ 
lim ───────────
n─→∞          5
     ⎛  n    ⎞ 
     ⎜ ___   ⎟ 
     ⎜ ╲     ⎟ 
     ⎜  ╲   i⎟ 
     ⎜  ╱    ⎟ 
     ⎜ ╱     ⎟ 
     ⎜ ‾‾‾   ⎟ 
     ⎝i = 1  ⎠ 
32
──
25
32
──
25
True

a = 9, b = 2
              3 
    ⎛  n     ⎞  
    ⎜ ___    ⎟  
    ⎜ ╲      ⎟  
    ⎜  ╲    9⎟  
    ⎜  ╱   i ⎟  
    ⎜ ╱      ⎟  
    ⎜ ‾‾‾    ⎟  
    ⎝i = 1   ⎠  
lim ────────────
n─→∞          10
    ⎛  n     ⎞  
    ⎜ ___    ⎟  
    ⎜ ╲      ⎟  
    ⎜  ╲    2⎟  
    ⎜  ╱   i ⎟  
    ⎜ ╱      ⎟  
    ⎜ ‾‾‾    ⎟  
    ⎝i = 1   ⎠  
59049
─────
 1000
59049
─────
 1000
True

a = 5, b = 5
lim 1
n─→∞ 
1
1
True

a = 10, b = 10
lim 1
n─→∞ 
1
1
True

$

HTML5

<div id="graph0"></div>
<pre id="output0"></pre>
<label for="r0">r = </label>
<input id="r0" type="number" min="0" value="2">
<label for="dx">dx = </label>
<input id="dx" type="number" min="0" step="0.0001" value="1">
<br>
<label for="x1">x1 = </label>
<input id="x1" type="number" value="1">
<label for="x2">x2 = </label>
<input id="x2" type="number" value="10">
<br>
<label for="y1">y1 = </label>
<input id="y1" type="number" value="0">
<label for="y2">y2 = </label>
<input id="y2" type="number" value="1.1">
<br>

<label for="a0">a = </label>
<input id="a0" type="number" min="0.1" value="2">
<label for="b0">b = </label>
<input id="b0" type="number" min="0.1" value="3">

<button id="draw0">draw</button>
<button id="clear0">clear</button>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.6/d3.min.js" integrity="sha256-5idA201uSwHAROtCops7codXJ0vja+6wbBrZdQ6ETQc=" crossorigin="anonymous"></script>

<script src="sample3.js"></script>    

JavaScript

let div0 = document.querySelector('#graph0'),
    pre0 = document.querySelector('#output0'),
    width = 600,
    height = 600,
    padding = 50,
    btn0 = document.querySelector('#draw0'),
    btn1 = document.querySelector('#clear0'),
    input_r = document.querySelector('#r0'),
    input_dx = document.querySelector('#dx'),
    input_x1 = document.querySelector('#x1'),
    input_x2 = document.querySelector('#x2'),
    input_y1 = document.querySelector('#y1'),
    input_y2 = document.querySelector('#y2'),
    input_a0 = document.querySelector('#a0'),
    input_b0 = document.querySelector('#b0'),    
    inputs = [input_r, input_dx, input_x1, input_x2, input_y1, input_y2,
              input_a0, input_b0],
    p = (x) => pre0.textContent += x + '\n',
    range = (start, end, step=1) => {
        let res = [];
        for (let i = start; i < end; i += step) {
            res.push(i);
        }
        return res;
    };

let draw = () => {
    pre0.textContent = '';

    let r = parseFloat(input_r.value),
        dx = parseFloat(input_dx.value),
        x1 = parseFloat(input_x1.value),
        x2 = parseFloat(input_x2.value),
        y1 = parseFloat(input_y1.value),
        y2 = parseFloat(input_y2.value),
        a = parseFloat(input_a0.value),
        b = parseFloat(input_b0.value);
    
    if (r === 0 || dx === 0 || x1 > x2 || y1 > y2) {
        return;
    }

    let points = [],
        y3 = (b + 1) ** (a + 1) / (a + 1) ** (b + 1),
        lines = [[x1, y3, x2, y3, 'blue']],
        f = (x) =>
        range(1, x + 1).reduce((prev, i) => prev + i ** a, 0) ** (b + 1) /
        range(1, x + 1).reduce((prev, i) => prev + i ** b, 0) ** (a + 1),
        fns = [[f, 'green']];

    fns
        .forEach((o) => {
            let [fn, color] = o;
            
            for (let x = x1; x <= x2; x += dx) {
                let y = fn(x);
                
                if (Math.abs(y) < Infinity) {
                    points.push([x, y, color]);
                }
            }
        });
    b
    
    let xscale = d3.scaleLinear()
        .domain([x1, x2])
        .range([padding, width - padding]);

    let yscale = d3.scaleLinear()
        .domain([y1, y2])
        .range([height - padding, padding]);

    let xaxis = d3.axisBottom().scale(xscale);
    let yaxis = d3.axisLeft().scale(yscale);
    div0.innerHTML = '';
    let svg = d3.select('#graph0')
        .append('svg')
        .attr('width', width)
        .attr('height', height);

    svg.selectAll('circle')
        .data(points)
        .enter()
        .append('circle')
        .attr('cx', (d) => xscale(d[0]))
        .attr('cy', (d) => yscale(d[1]))
        .attr('r', r)
        .attr('fill', (d) => d[2] || 'green');

    svg.selectAll('line')
        .data([[x1, 0, x2, 0], [0, y1, 0, y2]].concat(lines))
        .enter()
        .append('line')
        .attr('x1', (d) => xscale(d[0]))
        .attr('y1', (d) => yscale(d[1]))
        .attr('x2', (d) => xscale(d[2]))
        .attr('y2', (d) => yscale(d[3]))
        .attr('stroke', (d) => d[4] || 'black');
    
    svg.append('g')
        .attr('transform', `translate(0, ${height - padding})`)
        .call(xaxis);

    svg.append('g')
        .attr('transform', `translate(${padding}, 0)`)
        .call(yaxis);
    p(fns.join('\n'));
};

inputs.forEach((input) => input.onchange = draw);
btn0.onclick = draw;
btn1.onclick = () => pre0.textContent = '';
draw();








0 コメント:

コメントを投稿

Comments on Google+: