(** ESERCIZIO 2.1.10 **)

Clear[f];
f[x_]:=x^2-3;
Plot[f[x],{x,0,3},PlotStyle->{RGBColor[0,0,1],Thickness[0.005]}]

a=1.0;b=2.0;
tol=10^(-4);
fa=f[a];
fb=f[b];
an[0]=a;bn[0]=b;
cn[0]=0.5*(a+b);
test=b-a;
testbis[0]=bn[0]-an[0];
nmax=10;
n=1;While[test>tol,{fa=f[an[n-1]];fc=f[cn[n-1]];If[fa*fc<0,{an[n]=an[n-1];bn[n]=cn[n-1]},{an[n]=cn[n-1];bn[n]=bn[n-1]}];cn[n]=0.5*(an[n]+bn[n]);test=Abs[bn[n]-an[n]];n++}];
Print["Bisezione: n = ", n-1, "  c = ", cn[n-1]]
Clear[x];test=1.0;n=0;
x[0]=0.4;
While[test>tol,{x[n+1]=x[n]-f[x[n]]/f'[x[n]];test=Abs[x[n+1]-x[n]];n++}]
Print["Newton: n = ", n, "  c = ", x[n]]
Print["(Sqrt[3]) = ", Sqrt[3.]]

(** ESERCIZIO 2.1.11 **)

(** ESERCIZIO 2.1.12 **)

Clear[f];
f[x_]:=x^3+x-4;
a=1.; b=4.;
nmax1=Log[2,(b-a)/tol]

(** ESERCIZIO 2.1.17 **)

Clear[f,V,r,h,L];
f[h_]:=L*(r^2*(0.5*Pi-ArcSin[h/r])-h*(r^2-h^2));
dati={L->10.,r->1.,V->12.4}
Plot[(f[h]-V)/.dati,{h,0,r/.dati},PlotStyle->{RGBColor[0,0,1],Thickness[0.005]}]

a=0.0;b=0.2;
tol=10^(-2);
f1[h_]:=(f[h]-V)/.dati
fa=f1[a]/.dati
fb=f1[b]/.dati

an[0]=a;bn[0]=b;
cn[0]=0.5*(a+b);
test=b-a;
testbis[0]=bn[0]-an[0];
nmax=10;
n=1;While[test>tol,{fa=f1[an[n-1]];fc=f1[cn[n-1]];If[fa*fc<0,{an[n]=an[n-1];bn[n]=cn[n-1]},{an[n]=cn[n-1];bn[n]=bn[n-1]}];cn[n]=0.5*(an[n]+bn[n]);test=Abs[bn[n]-an[n]];n++}];
Print["Bisezione: n = ", n-1, "  c = ", cn[n-1]]