0

So we have a fixed point function and were asked to choose an epsilon ( tolerance) that would give us an approximation of the root with 8 significant numbers.

The root is 1 so we would like a result that gives us 1,234567 ( 8 significant numbers)

My question is how am i supposed to guess that ? I know we have the formula :

$\Delta x\leq 0.5\quad X \quad 10^-m $ (exponent -m) But i am not sure what plays the role of $\Delta x$ here i think it's $errel$ but i am not sure.

Also when i check the output in the console it's always an answer with 5 significant numbers no matter what i change the epsilon to so i am a bit confused.

Thanks for your help.

The function

function [x] = pointfixe(g, x0, N, epsilon)

x(1)=x0;

x1=g(x0);

e_n=abs(x1-x0); errel=e_n/abs(x1);

nbiterations=1; while (errel > epsilon) & (nbiterations <N) x0=x1; x1=g(x0); e_n_1=e_n; e_n=abs(x1-x0); errel=e_n/abs(x1); nbiterations=nbiterations+1; x(nbiterations)=x1; disp(x); end end

My script

clear;close all;clc;

g1 = @(x) -0.25* (x^3 - 3*x^2 - 2); x0 = 1.5;

epsilon = 1e-7;

N=50;

pointfixe(g1, x0, N, epsilon);

A part of the console imput to show you an example about what i mean by 5 significant numbers

enter image description here

Edit from this output how can i analyze if the number of significant numbers is 8, how can i judge which epsilon will give me 8 significant numbers

enter image description here

New edit

enter image description here

codetime
  • 335
  • 2
  • 8
  • 1
    Have you tried 'format long'? – Mape Oct 09 '20 at 00:44
  • @Mape No i am new to matlab, where would i put that ? Thanks for reply. – codetime Oct 09 '20 at 00:45
  • Anywhere in the script, it will expand the numbers shown in the output. See https://se.mathworks.com/help/matlab/matlab_env/format-output.html for more info – Mape Oct 09 '20 at 00:46
  • @Mape Ok yea this helps to show more significant numbers in the console, but i don't think it solves my problem since in the console even if i change the epsilon, my numbers always has the same significant numbers. I added an edit – codetime Oct 09 '20 at 00:53

2 Answers2

0

Keep in mind that no criteria will be independent of the particular function $g$. When you estimate the error by computing the difference between consecutive iterates (the abs(x1-x0) in your code), this is not an actual upper bound. What you can prove from the fixed point theorem (if the conditions hold) is that

$$ \underbrace{|x_n - z|}_{\textrm{error}}\leq \frac{L}{1-L} |x_n - x_{n-1}|. $$

So you see that the difference $|x_n-x_{n-1}|$ is only an upper bound for the error if $L$ (the contractivity constant) is $\leq \frac 12$.

For instance, if $L=0.99$, you have that $L/(1-L) = 99$, so the actual error can be two orders of magnitude larger than the difference $|x_n-x_{n-1}|$.

That being said, since you are able to "sort of" estimate the error in each iteration, if you want to get $d$ significant digits, just iterate until the relative error is less than $0.5 \times 10^{-d}$.

note: Depending on the authors, the number of significant digits can be defined in terms of the relative error (I think this is more useful) or the absolute error.

PierreCarre
  • 20,974
  • 1
  • 18
  • 34
  • Ok so if i understand i change the epsilon until my last relative error (errel) is less than $0.5X10^-d $ so it has nothing to do with the point fixe vector that i output ? I can just print errel and verify what is the last value and if it's less than 0.5 X... if not i change my epsilon until it is. Do i understand this right ? Thanks a lot. – codetime Oct 09 '20 at 14:25
  • @codetime The output does not mean much... As others pointed out, it can even be a mater of formating in the displayed numbers. What is relevant is the estimated relative error. As you say, you just need to adjust epsilon to be $0.5 \times 10^{-d}$. But I stress the fact that this does not guarantee that you actually have d correct digits, unless you have an upper bound for L and replace one of the cycle conditions according to the criteria in my answer. – PierreCarre Oct 09 '20 at 14:34
  • ok i am not sure if i understand clearly, see my last added photo in the post. I obtain a last errel of 0.000 000 007 and my epsilon is exponent -8 so $0.5X10^-8$ is 0. 000 000 005 and right now i am at 58 iterations ( N=58) and the program won't let me go above 58 because the condition is reached. So i am never able to be lower than $0.5X10^-8$ so there's something i don't understand thanks.. – codetime Oct 09 '20 at 17:26
0

You are considering the functional iteration $$x_{n+1} = g(x_n)$$ where $$g(x) = \frac{1}{4}(x^3 - 3 x^2 - 2)$$ and $x_0 = \frac{3}{2}$. You seek to recover the fixed point $x=1$ with a relative error which is less than $\tau = 10^{-8}/2$. We begin by considering the interval $I = [\frac{1}{2}, \frac{3}{2}]$ which contains $x_0$ and is centered around $x=1$. We have $$g'(x) = \frac{1}{4} (3x^2 - 6x) = \frac{3}{4} x (x-2).$$ A short calculations show that $|g'(x)| \leq \frac{3}{4}$ for $x \in I$. This shows that convergence sets in immediately and that we may choose $L=\frac{3}{4}$. You can now deploy the bound suggested by @PierreCarre, i.e., $$ |x-x_n| \leq \frac{L}{1-L} |x_n - x_{n-1}| = \frac{\frac{3}{4}}{\frac{1}{4}}|x_n - x_{n-1}| = 3|x_n - x_{n-1}|.$$ Since the target value is $x=1$ this observation allows you to bound the relative error. You need to iterate until $|x_n-x_{n-1}| \leq \tau$. As @PierreCarre correctly points out this analysis hinges on the choice of the function $g$.

Algorithms which attempts to detect convergence by monitoring $x_n - x_{n-1}$ can always be defeated by a sufficiently complicated function. Detail are presented in this answer to a question related to the termination of Newton's method.

Carl Christian
  • 12,583
  • 1
  • 14
  • 37
  • Thanks for reply, if you look at my last comment on Pierre post and which is related to my last picture in my post where i print the relative errors. It seems that i always come close to a value $xn-xn-1$ <= $T$ but the code always stop before because of the conditions. So i am kinda confused. Thanks And it seems to be like that for any N used and tolerance. – codetime Oct 10 '20 at 22:49
  • @codetime You are converging linearly as you should. Increase $N$ to about 65 to meet the required tolerance. – Carl Christian Oct 10 '20 at 23:00
  • Ok idk what i don't understand but i never reach a number below T am i looking the wrong thing let's say i choose N =65 and epsilon= 1e-8 i get a last relative error of 7.9234e-06. Just to show that no matter what i choose epsilon / 2 will always be smaller – codetime Oct 11 '20 at 00:12
  • @codetime I cannot replicate your problem. I have run function and your script without any problem. The fact that your current function underestimates the relative error by a factor of 3 is cannot explain why you get a relative error of $7.9234 \times 10^{-6}$. There must be some other problem. – Carl Christian Oct 11 '20 at 16:38
  • mmm let's say i use epsilon = 1e-8 and N=58, my last errel printed will be 7.9505e-09 , no matter what i choose i will be above 0.5e-8 so i don't get it. What epsilon would u choose to get 8 significant numbers ? thanks again. – codetime Oct 11 '20 at 17:51
  • @codetime Your program thinks that the relative error is $1/3$ of the actual value. You want a relative error of $\frac{1}{2} \times 10^{-8}$, to get $8$ significant figures, so use $\epsilon = \frac{1}{6} \times 10^{-8}$. A good experiment would be to set $\epsilon=0$ and $N=200$. By examining the output you will be able to find the exact result for yourself. It can simpler to explain a result when you know it, than finding from scratch. – Carl Christian Oct 12 '20 at 09:32
  • oh i thought i only had to play with the exponent... Maybe this is why i was so confused and didn't get the results i wante.. thanks.. – codetime Oct 12 '20 at 20:38
  • @codetime Has the problem been resolved? – Carl Christian Oct 12 '20 at 21:15
  • Yes, thanks a lot. – codetime Oct 13 '20 at 19:59