(** Esercizio 4.3.9 **)

n=0;
f[x_]:=Sum[a[k]*x^k,{k,0,n}]
f[x]

integrale=Integrate[f[x],{x,-1,1}]
quadratura=f[-(Sqrt[3])/3]+f[(Sqrt[3])/3]
integrale-quadratura

(* Era necessario? *)

f[x_]:=1
f[x]
integrale=Integrate[f[x],{x,-1,1}]
quadratura=f[-(Sqrt[3])/3]+f[(Sqrt[3])/3]
integrale-quadratura

(** Esercizio 4.3.10 **)

n=0;
f[x_]:=Sum[a[k]*x^k,{k,0,n}]
f[x]

h=(b-a)/3;
x[0]=a;
x[1]=a+h;
x[2]=b;
integrale=Integrate[f[x],{x,a,b}]
quadratura=3*h/4*(3*f[x[1]]+f[x[2]])
integrale-quadratura

Simplify[integrale-quadratura]

(** Esercizio 4.3.11 **)

Clear[f0,f1,f2,b0,b1,b2];
f0[x_]:=1;
b0=Integrate[f0[x],{x,-1,1}]
f1[x_]:=x;
b1=Integrate[f1[x],{x,-1,1}]
f2[x_]:=x^2;
b2=Integrate[f2[x],{x,-1,1}]

Clear[eq0,eq1,eq2,c0,c1,c2];
eq0=c0*f0[-1]+c1*f0[0]+c2*f0[1]==b0
eq1=c0*f1[-1]+c1*f1[0]+c2*f1[1]==b1
eq2=c0*f2[-1]+c1*f2[0]+c2*f2[1]==b2

Solve[{eq0,eq1,eq2},{c0,c1,c2}]

(** Esercizio 4.3.13 **)