I have to program something but I don't understand the task. I'm not sure if this is the right place to ask but I thought I can try.
I have to approximate $\pi$ with the BBP formula. $\displaystyle\pi=\sum_{k=0}^\infty\dfrac{1}{16^k}\left(\dfrac{4}{8k+1}-\dfrac{2}{8k+4}-\dfrac{1}{8k+5}-\dfrac{1}{8k+6}\right).$
I have to write a function $function [mpi, jmax] = mypi(tol)$. This function should approximate $\pi$ with accuracy $tol$. The criteria to stop the loop should be the difference of two iterated values. $jmax$ is the number of iterations. The goal is to calculate $jmax$ for $tol = 10^{-10}$.
I don't understand what the difference of two iterated values should be. So far I programmed a function $f(k)$ and with $f(0) + f(1)+f(2)+f(3)$ I'm getting $3.141592457567436$, the first $6$ digits after the decimal point are correct. So which values should be used to calculate a difference? The last $2$? So $f(2)$ and $f(3)$? I don't know why that would make sense. And I also don't understand what $10^{-10}$ is supposed to mean. Does the task want me to calculate the first $10$ digits of $\pi$?
I already did that and $jmax$ was wrong, so I don't think that it means that. I'm allowed to calculate the difference between $\pi$ and my approximation, that was a previous exercise, not sure if that helps.
Hint
Forget about $\pi$. Let $$a_k=\dfrac{1}{16^k}\left(\dfrac{4}{8k+1}-\dfrac{2}{8k+4}-\dfrac{1}{8k+5}-\dfrac{1}{8k+6}\right)$$ and you want to compute $p$ such that $$a_{p+1} \leq 10^{-n}$$ since this is the difference between two iterated values.
Assume that $p$ is large and by series expansion approximate $a_{p+1}$. This gives a rather simple equation to solve in the real domain ; when done, as usual, retain $\lceil p \rceil$.
Just for your curiosity, there is an explicit solution for general $n$ but this is out of topic.