Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
x1=2
Nmax=10
epsilon=0.0001
fHxL := Cos@xD
In[27]:= x0 = 0;
x1 = 2.0;
Nmax = 10;
eps = 0.000000000001;
f@x_D := Cos@xD;
If@N@f@x0D * f@x1DD > 0,
Print@"These values do not satisfy the IVP so change the values."D,
If @Abs@x1 - x0D < eps, Return@N@x1, 8DD,
For@ i = 1, i <= Nmax , i ++, a = N@x1 - f@x1D * Hx1 - x0L Hf@x1D - f@x0DL, 8D;
If @f@aD * f@x1D > 0, x1 = a, x0 = aD; If @Abs@x1 - x0D < eps, Return@N@a, 8DDD;
Print@i, "th iteration value is : ", N@a, 8DD;
Print@" Estimated error is : ", N@x1 - x0, 8DDDD;
Print@" Root is : ", N@a, 8DD; Print@" Estimated error is : ", N@x1 - x0, 8DDD;
Plot@f@xD, 8x, - 1, 3<, PlotRange ® 8- 1, 1<, PlotStyle ® Red, PlotLabel ® "f@xD= " f@xD,
AxesLabel ® 8x, f@xD<, AspectRatio ® Automatic, Frame ® True, GridLines ® Automatic,
ClippingStyle ® Automatic, Filling ® Axis, FillingStyle ® LightBrownD
Untitled-1 3
0.5
Out[33]=
0.0 x
-0.5
-1.0
-1 0 1 2 3