I am trying to solve the fifty problems $f_i(\theta) = 0, \ i = 1, ..., 50,$ where
$$f_i (\theta) = \theta - \sin(\theta) - \frac{i}{100}$$
I was told I must solve these in ascending order of $i$ and with a maximum of 200 evaluations of $f$ or its derivatives.
I tried to solve this in Matlab using Newton's method, with the following iteration formula:
$$\theta_{n+1} = \theta_n - \frac{f(\theta_n)}{f'(\theta_n)} = \theta_n - \frac{\theta_n- \sin(\theta_n) - \frac{i}{100}}{1- cos(\theta_n)}$$
Here's my basic Matlab code for one iteration applied to each problem:
x=0.01;
for i=1:1:50
x=x - ((x-sin(x)-(i/100))/(1-(cos(x))))
end
However I think the question asks for 200 iterations per problem, so I modified the code to:
for i=1:1:50
n_itn=200;
x(1)=0.01;
for k = 1:n_itn
x(k+1)=x(k) - ((x(k)-sin(x(k))-(i/100))/(1-(cos(x(k)))))
end
end
But I get an extremely long answer, here's a part of it:
Columns 196 through 198
-0.000004145710670 -0.000002034384641 -0.000000336803024
Columns 199 through 201
-0.000000117100873 0.000000102162712 -0.000150151084928
So, I am not sure which part of this is my solution. So, what is wrong with my code? Am I even on the right track?
Any help would be greatly appreciated.
I think the aim of this task is to teach you the wonders of the homotopy continuation method. Thus the goal is to solve $$ x-\sin x =\frac12 $$ which then gets subdivided into 50 steps raising the "watermark" of the right side from $0$ to $\frac12$, where the initial problem $$ x-\sin x=0 $$ has the easy (and unique) solution $x_0=0$.
The idea is that if $x_k$ is a good solution to $$ x-\sin x=\frac{k}{100} $$ then the error $f_{k+1}(x_k)=-\frac1{100}$ leads after two Newton iterations to an error of magnitude $(0.01)^{2^2}=10^{-8}$.
Two Newton iterations because 200 evaluations of $f$ and $f'$ for 50 problems leads to an average of 4 evaluations equal to 2 Newton steps.
Since the solution for $k=0$ is singular, one can not start the iteration for $x_1$ with $x=x_0=0$. Better approximate $x-\sin x\simeq\frac16x^3$ and thus start the iteration with $x=\sqrt[3]{\frac3{50}}=0.3914867641169…$ for $k=1$ and similar for further small $k$. Then use linear extrapolation to get good initial values. (Basic homotopy uses constant continuation.)
leading to results (partial list