## 2016年11月30日水曜日

### 数学 - 解析学 - JavaScript - 数列と級数 - 数列の収束条件(下に有界な単調減少数列、極限値)

$\begin{array}{l}{a}_{1}{}^{2}=1<2\\ {a}_{n}{}^{2}<2\\ と仮定する\\ {a}_{n+1}{}^{2}=6+{a}_{n}<6+2<8\\ {a}_{1}^{2}<10\\ \left({a}_{n}\right)は有界。\\ {a}_{n}-{a}_{n+1}\\ ={a}_{n}-\sqrt{6+{a}_{n}}\\ <2-\sqrt{6}\\ <0\\ 単調減少で下に有界なので収束する。\\ \underset{n\to \infty }{\mathrm{lim}}{a}_{n}=\alpha \\ \alpha =\sqrt{6+\alpha }\\ {\alpha }^{2}=6+\alpha \\ \left(\alpha -3\right)\left(\alpha +2\right)=0\\ \alpha >0より\\ \underset{n\to \infty }{\mathrm{lim}}{a}_{n}=3\end{array}$

HTML5

<div id="graph0"></div>
<div id="output0"></div>
<label for="n0">n = </label>
<input id="n0" type="number" min="1" value="10">

<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="sample2.js"></script>


JavaScript

{
let div_graph = document.querySelector('#graph0'),
div_output = document.querySelector('#output0'),
input_n = document.querySelector('#n0'),
width = 600,
height = 600,

let f = (prev) => {
return Math.sqrt(6 + prev);
};
let getPoints = (n) => {
let prev = 1,
result = [[1, prev]];n

for (let i = 2; i <= n; i += 1) {
let next = f(prev);
result.push([i, next]);
prev = next;
}
return result;
}
let plot = () => {
let n = parseInt(input_n.value, 10),
points = getPoints(n);

let xscale = d3.scaleLinear()
.domain([1, n])
let yscale = d3.scaleLinear()
.domain([points[0][1], 4])

console.log(points.map((x) => x[1]));
div_graph.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', 2)
.attr('color', 'green');

let xaxis = d3.axisBottom().scale(xscale);
let yaxis = d3.axisLeft().scale(yscale);

svg.append('line')
.attr('x1', xscale(1))
.attr('y1', yscale(3))
.attr('x2', xscale(n))
.attr('y2', yscale(3))
.attr('stroke', 'red');

svg.append('g')
.attr('transform', translate(0, ${height - padding})) .call(xaxis); svg.append('g') .attr('transform', translate(${padding}, 0))
.call(yaxis);

div_output.innerHTML = points.map((x) => ${x[0]}:${x[1]}).join('<br>');
};

input_n.onchange = plot;
plot();

}