Algorithm and programming for sequences

The question involves writing, completing, or analyzing a program (typically Python) that computes sequence terms or finds a threshold/rank related to convergence.

bac-s-maths 2013 Q2a 5 marks View
Exercise 2 — Candidates WHO HAVE NOT FOLLOWED the mathematics specialization course
We consider the sequence $( u _ { n } )$ defined by $u _ { 0 } = 1$ and, for every natural integer $n$, $$u _ { n + 1 } = \sqrt { 2 u _ { n } } .$$
  1. We consider the following algorithm:

Variables:$n$ is a natural integer
$u$ is a positive real number
Initialization:Request the value of $n$
Assign to $u$ the value 1
Processing:For $i$ varying from 1 to $n :$
$\mid$ Assign to $u$ the value $\sqrt { 2 u }$
End of For
Output :Display $u$

a. Give an approximate value to $10 ^ { - 4 }$ of the result displayed by this algorithm when $n = 3$ is chosen. b. What does this algorithm allow us to calculate? c. The table below gives approximate values obtained using this algorithm for certain values of $n$.
$n$15101520
Displayed value1,41421,95711,99861,99991,9999

What conjectures can be made concerning the sequence $\left( u _ { n } \right)$ ?
2. a. Prove that, for every natural integer $n , 0 < u _ { n } \leqslant 2$. b. Determine the direction of variation of the sequence $( u _ { n } )$. c. Prove that the sequence $( u _ { n } )$ is convergent. We do not ask for the value of its limit.
3. We consider the sequence $( v _ { n } )$ defined, for every natural integer $n$, by $v _ { n } = \ln u _ { n } - \ln 2$. a. Prove that the sequence $\left( v _ { n } \right)$ is a geometric sequence with ratio $\frac { 1 } { 2 }$ and first term $v _ { 0 } = - \ln 2$. b. Determine, for every natural integer $n$, the expression of $v _ { n }$ as a function of $n$, then of $u _ { n }$ as a function of $n$. c. Determine the limit of the sequence $\left( u _ { n } \right)$. d. Copy the algorithm below and complete it with the instructions for processing and output, so as to display as output the smallest value of $n$ such that $u _ { n } > 1,999$.
Variables:$n$ is a natural integer
$u$ is a real number
Initialization :Assign to $n$ the value 0
Assign to $u$ the value 1
Processing:
Output :
bac-s-maths 2013 Q2 5 marks View
Let two sequences $\left( u _ { n } \right)$ and $\left( v _ { n } \right)$ be defined by $u _ { 0 } = 2$ and $v _ { 0 } = 10$ and for every natural number $n$,
$$u _ { n + 1 } = \frac { 2 u _ { n } + v _ { n } } { 3 } \quad \text { and } \quad v _ { n + 1 } = \frac { u _ { n } + 3 v _ { n } } { 4 } .$$
PART A
Consider the following algorithm:
\begin{verbatim} Variables: N is an integer U,V,W are real numbers K is an integer Start: Assign 0 to K Assign 2 to U Assign 10 to V Input N While KExecute this algorithm by inputting $N = 2$. Copy and complete the table given below showing the state of the variables during the execution of the algorithm.
$K$$W$$U$$V$
0
1
2

PART B
1. a. Show that for every natural number $n , v _ { n + 1 } - u _ { n + 1 } = \frac { 5 } { 12 } \left( v _ { n } - u _ { n } \right)$.
b. For every natural number $n$ let $w _ { n } = v _ { n } - u _ { n }$.
Show that for every natural number $n , w _ { n } = 8 \left( \frac { 5 } { 12 } \right) ^ { n }$.
2. a. Prove that the sequence $( u _ { n } )$ is increasing and that the sequence $( v _ { n } )$ is decreasing.
b. Deduce from the results of questions 1. b. and 2. a. that for every natural number $n$ we have $u _ { n } \leqslant 10$ and $v _ { n } \geqslant 2$.
c. Deduce that the sequences $\left( u _ { n } \right)$ and $\left( v _ { n } \right)$ are convergent.
3. Show that the sequences $( u _ { n } )$ and $( v _ { n } )$ have the same limit.
4. Show that the sequence $( t _ { n } )$ defined by $t _ { n } = 3 u _ { n } + 4 v _ { n }$ is constant.
Deduce that the common limit of the sequences $\left( u _ { n } \right)$ and $\left( v _ { n } \right)$ is $\frac { 46 } { 7 }$.
bac-s-maths 2013 Q4 (non-specialization) View
The purpose of this exercise is the study of the sequence $(u_n)$ defined by its first term $u_1 = \frac{3}{2}$ and the recurrence relation: $u_{n+1} = \frac{n u_n + 1}{2(n+1)}$.
Part A - Algorithms and conjectures
To calculate and display the term $u_9$ of the sequence, a student proposes the algorithm below. He forgot to complete two lines.
Variables$n$ is a natural integer, $u$ is a real number
InitializationAssign to $n$ the value 1, Assign to $u$ the value 1.5
TreatmentWhile $n < 9$, Assign to $u$ the value $\cdots$, Assign to $n$ the value $\cdots$, End While
OutputDisplay the variable $u$

  1. Copy and complete the two lines of the algorithm where there are ellipses.
  2. How would this algorithm need to be modified so that it calculates and displays all terms of the sequence from $u_2$ to $u_9$?
  3. With this modified algorithm, the following results were obtained, rounded to the nearest ten-thousandth:
    n123456$\ldots$99100
    $u_n$1.50.6250.3750.26560.20630.1693$\ldots$0.01020.0101

    In light of these results, conjecture the direction of variation and convergence of the sequence $(u_n)$.

Part B - Mathematical study
We define an auxiliary sequence $(v_n)$ by: for all integer $n \geqslant 1, v_n = n u_n - 1$.
  1. Show that the sequence $(v_n)$ is geometric; specify its common ratio and its first term.
  2. Deduce that, for all natural integer $n \geqslant 1$, we have: $u_n = \frac{1 + (0.5)^n}{n}$.
  3. Determine the limit of the sequence $(u_n)$.
  4. Justify that, for all integer $n \geqslant 1$, we have: $u_{n+1} - u_n = -\frac{1 + (1 + 0.5n)(0.5)^n}{n(n+1)}$. Deduce the direction of variation of the sequence $(u_n)$.

Part C - Return to algorithms
Inspired by part A, write an algorithm to determine and display the smallest integer $n$ such that $u_n < 0.001$.
bac-s-maths 2015 Q4 View
(Candidates who have not followed the specialization course)
Part A
We consider the following algorithm:
\begin{tabular}{l} Variables:
Input: Processing:
Output:
&
$k$ and $p$ are natural integers
$u$ is a real number
Ask for the value of $p$
Assign to $u$ the value 5
For $k$ varying from 1 to $p$
Assign to $u$ the value $0,5u + 0,5(k-1) - 1,5$
End for
Display $u$
\hline \end{tabular}
Run this algorithm for $p = 2$ by indicating the values of the variables at each step. What number do we obtain as output?
Part B
Let $(u_n)$ be the sequence defined by its first term $u_0 = 5$ and, for every natural integer $n$ by $$u_{n+1} = 0,5u_n + 0,5n - 1,5.$$
  1. Modify the algorithm from the first part to obtain as output all the values of $u_n$ for $n$ varying from 1 to $p$.
  2. Using the modified algorithm, after entering $p = 4$, we obtain the following results:
    $n$1234
    $u_n$1$-0,5$$-0,75$$-0,375$

    Can we assert, based on these results, that the sequence $(u_n)$ is decreasing? Justify.
  3. Prove by induction that for every natural integer $n$ greater than or equal to 3, $u_{n+1} > u_n$. What can we deduce about the monotonicity of the sequence $(u_n)$?
  4. Let $(v_n)$ be the sequence defined for every natural integer $n$ by $v_n = 0,1u_n - 0,1n + 0,5$. Prove that the sequence $(v_n)$ is geometric with ratio 0,5 and express $v_n$ as a function of $n$.
  5. Deduce that, for every natural integer $n$, $u_n = 2^{1-n} \cdot 5 + n - 5$ (or the equivalent closed form expression for $u_n$ as a function of $n$).
bac-s-maths 2015 Q4a 5 marks View
(For candidates who have not followed the specialization course)
We consider two sequences of real numbers $( d _ { n } )$ and $( a _ { n } )$ defined by $d _ { 0 } = 300$, $a _ { 0 } = 450$ and, for every natural number $n \geqslant 0$
$$\left\{ \begin{array} { l } d _ { n + 1 } = \frac { 1 } { 2 } d _ { n } + 100 \\ a _ { n + 1 } = \frac { 1 } { 2 } d _ { n } + \frac { 1 } { 2 } a _ { n } + 70 \end{array} \right.$$
  1. Calculate $d _ { 1 }$ and $a _ { 1 }$.
  2. It is desired to write an algorithm that allows displaying as output the values of $d _ { n }$ and $a _ { n }$ for an integer value of $n$ entered by the user. The following algorithm is proposed:
    Variables:\begin{tabular}{l} $n$ and $k$ are natural numbers
    $D$ and $A$ are real numbers
    \hline Initialization: &
    $D$ takes the value 300
    $A$ takes the value 450
    Enter the value of $n$
    \hline Processing: &
    For $k$ varying from 1 to $n$
    $D$ takes the value $\frac { D } { 2 } + 100$
    $A$ takes the value $\frac { A } { 2 } + \frac { D } { 2 } + 70$
    End for
    \hline Output: &
    Display $D$
    Display $A$
    \hline \end{tabular}
    a. What numbers are obtained as output of the algorithm for $n = 1$? Are these results consistent with those obtained in question 1? b. Explain how to correct this algorithm so that it displays the desired results.
  3. a. For every natural number $n$, we set $e _ { n } = d _ { n } - 200$. Show that the sequence $( e _ { n } )$ is geometric. b. Deduce the expression of $d _ { n }$ as a function of $n$. c. Is the sequence $( d _ { n } )$ convergent? Justify.
  4. We admit that for every natural number $n$,
    $$a _ { n } = 100 n \left( \frac { 1 } { 2 } \right) ^ { n } + 110 \left( \frac { 1 } { 2 } \right) ^ { n } + 340 .$$
    a. Show that for every integer $n$ greater than or equal to 3, we have $2 n ^ { 2 } \geqslant ( n + 1 ) ^ { 2 }$. b. Show by induction that for every integer $n$ greater than or equal to 4, $2 ^ { n } \geqslant n ^ { 2 }$. c. Deduce that for every integer $n$ greater than or equal to 4,
    $$0 \leqslant 100 n \left( \frac { 1 } { 2 } \right) ^ { n } \leqslant \frac { 100 } { n } .$$
    d. Study the convergence of the sequence $\left( a _ { n } \right)$.
bac-s-maths 2015 Q5a View
Exercise 5 — Candidates who have not chosen the specialisation option
Let ( $v _ { n }$ ) be the sequence defined by
$$v _ { 1 } = \ln ( 2 ) \text { and, for all natural integer } n \text { non-zero, } v _ { n + 1 } = \ln \left( 2 - \mathrm { e } ^ { - v _ { n } } \right) .$$
We admit that this sequence is defined for all non-zero natural integer $n$. We then define the sequence ( $S _ { n }$ ) for all non-zero natural integer $n$ by :
$$S _ { n } = \sum _ { k = 1 } ^ { n } v _ { k } = v _ { 1 } + v _ { 2 } + \cdots + v _ { n } .$$
The purpose of this exercise is to determine the limit of ( $S _ { n }$ ).
Part A - Conjectures using an algorithm
  1. Copy and complete the following algorithm which calculates and displays the value of $S _ { n }$ for a value of $n$ chosen by the user :
    Variables :
    $n , k$ integers
    $S , v$ real numbers
    Initialisation :
    Input the value of $n$
    $v$ takes the value $\ldots$
    $S$ takes the value $\ldots$
    Processing:
    For $k$ varying from \ldots to \ldots do
    \ldots takes the value \ldots
    \ldots takes the value \ldots
    End For
    Output :
    Display $S$

  2. Using this algorithm, we obtain some values of $S _ { n }$. The values rounded to the nearest tenth are given in the table below :
    $n$101001000100001000001000000
    $S _ { n }$2.44.66.99.211.513.8

    By explaining your approach, make a conjecture about the behaviour of the sequence $\left( S _ { n } \right)$.

Part B - Study of an auxiliary sequence
For all non-zero natural integer $n$, we define the sequence ( $u _ { n }$ ) by $u _ { n } = \mathrm { e } ^ { v _ { n } }$.
  1. Verify that $u _ { 1 } = 2$ and that, for all non-zero natural integer $n$, $u _ { n + 1 } = 2 - \frac { 1 } { u _ { n } }$.
  2. Calculate $u _ { 2 } , u _ { 3 }$ and $u _ { 4 }$. Results should be given in fractional form.
  3. Prove that, for all non-zero natural integer $n$, $u _ { n } = \frac { n + 1 } { n }$.

Part C - Study of ( $S _ { n }$ )
  1. For all non-zero natural integer $n$, express $v _ { n }$ as a function of $u _ { n }$, then $v _ { n }$ as a function of $n$.
  2. Verify that $S _ { 3 } = \ln ( 4 )$.
  3. For all non-zero natural integer $n$, express $S _ { n }$ as a function of $n$. Deduce the limit of the sequence $\left( S _ { n } \right)$.
bac-s-maths 2017 Q5a 5 marks View
Exercise 5 (5 points) — Candidates who have not followed the speciality course
Let $( u _ { n } )$ be the sequence defined by $u _ { 0 } = 3 , u _ { 1 } = 6$ and, for all natural integer $n$:
$$u _ { n + 2 } = \frac { 5 } { 4 } u _ { n + 1 } - \frac { 1 } { 4 } u _ { n } .$$
The purpose of this exercise is to study the possible limit of the sequence $( u _ { n } )$.
Part A:
We wish to calculate the values of the first terms of the sequence $( u _ { n } )$ using a spreadsheet. We have reproduced below part of a spreadsheet, where the values of $u _ { 0 }$ and $u _ { 1 }$ appear.
AB
1$n$$u _ { n }$
203
316
42
53
64
75

  1. Give a formula which, entered in cell B4, then copied downwards, allows obtaining values of the sequence $( u _ { n } )$ in column B.
  2. Copy and complete the table above. Approximate values to $10 ^ { - 3 }$ of $u _ { n }$ will be given for $n$ ranging from 2 to 5.
  3. What can be conjectured about the convergence of the sequence $( u _ { n } )$?

Part B: Study of the sequence
We consider the sequences $( v _ { n } )$ and $( w _ { n } )$ defined for all natural integer $n$ by:
$$v _ { n } = u _ { n + 1 } - \frac { 1 } { 4 } u _ { n } \quad \text { and } \quad w _ { n } = u _ { n } - 7 .$$
  1. a. Prove that $( v _ { n } )$ is a constant sequence. b. Deduce that, for all natural integer $n , u _ { n + 1 } = \frac { 1 } { 4 } u _ { n } + \frac { 21 } { 4 }$.
  2. a. Using the result of question 1. b., show by induction that, for all natural integer $n , u _ { n } < u _ { n + 1 } < 15$. b. Deduce that the sequence $( u _ { n } )$ is convergent.
  3. a. Prove that $( w _ { n } )$ is a geometric sequence and specify its first term and common ratio. b. Deduce that, for all natural integer $n , u _ { n } = 7 - \left( \frac { 1 } { 4 } \right) ^ { n - 1 }$. c. Calculate the limit of the sequence $( u _ { n } )$.
bac-s-maths 2023 Q3 5 marks View
We consider the sequence ( $u _ { n }$ ) such that $u _ { 0 } = 0$ and for all natural integer $n$ : $$u _ { n + 1 } = \frac { - u _ { n } - 4 } { u _ { n } + 3 } .$$ We admit that $u _ { n }$ is defined for all natural integer $n$.
  1. Calculate the exact values of $u _ { 1 }$ and $u _ { 2 }$.
  2. We consider the function term below written incompletely in Python language:

\begin{verbatim} def terme (n) : u = ... for i in range(n): u = ... return(u) \end{verbatim}
We recall that in Python language, «i in range (n) » means that $i$ varies from 0 to $n - 1$.
Rewrite and complete the box above so that, for all natural integer $n$, the instruction terme (n) returns the value of $u _ { n }$.
3. Let the function $f$ defined on $] - 3 ; + \infty [$ by: $$f ( x ) = \frac { - x - 4 } { x + 3 }$$ Thus, for all natural integer $n$, we have $u _ { n + 1 } = f \left( u _ { n } \right)$. Prove that the function $f$ is strictly increasing on $] - 3 ; + \infty [$.
4. Prove by induction that for all natural integer $n$ : $$- 2 < u _ { n + 1 } \leqslant u _ { n } .$$
  1. Deduce that the sequence ( $u _ { n }$ ) is convergent.
  2. Let the sequence $\left( v _ { n } \right)$ defined for all natural integer $n$ by:
$$v _ { n } = \frac { 1 } { u _ { n } + 2 }$$ a. Give $v _ { 0 }$. b. Prove that the sequence ( $v _ { n }$ ) is arithmetic with common difference 1 . c. Deduce that for all natural integer $n \geqslant 1$ : $$u _ { n } = \frac { 1 } { n + 0,5 } - 2 .$$ d. Determine the limit of the sequence $\left( u _ { n } \right)$.
bac-s-maths 2024 Q3 6 marks View
Consider the sequence $(u_n)$ defined by: $$u_0 = 8 \text{ and for every natural number } n,\quad u_{n+1} = u_n - \ln\left(\frac{u_n}{4}\right).$$
  1. a. Give the values rounded to the nearest hundredth of $u_1$ and $u_2$. b. Consider the mystery function defined below in Python. We admit that, for every strictly positive real number $a$, $\log(a)$ returns the value of the natural logarithm of $a$. \begin{verbatim} def mystery(k) : u = 8 S = 0 for i in range(k) : S = S + u u = u - log( u / 4) return S \end{verbatim} The execution of \texttt{mystery(10)} returns 58.44045206721732. What does this result represent? c. Modify the previous function so that it returns the average of the first $k$ terms of the sequence $(u_n)$.
  2. Consider the function $f$ defined and differentiable on $]0; +\infty[$ by: $$f(x) = x - \ln\left(\frac{x}{4}\right).$$ Study the variations of $f$ on $]0; +\infty[$ and draw its variation table. The exact value of the minimum of $f$ on $]0; +\infty[$ will be specified. Limits are not required.
    In the rest of the exercise, it will be noted that for every natural number $n$, $u_{n+1} = f(u_n)$.
  3. a. Prove, by induction, that for every natural number $n$, we have: $$1 \leqslant u_{n+1} \leqslant u_n.$$ b. Deduce that the sequence $(u_n)$ converges to a real limit.
    Let $\ell$ denote the value of this limit. c. Solve the equation $f(x) = x$. d. Deduce the value of $\ell$.