(*First homework problem: precision*)

f[x_,y_]:=(((((x+y))^2)-2*x*y-(y^2))/(x^2));
Table[f[(10.0^(-i)),(10^3)] ,{i,1,7}]
Table[f[(10^(-i)),(10^3)],{i,1,7}]

(*Riemann sum problem*)

g[x_]:=(x^2);
Δx=.025;
Sum[g[x]Δx,{x,-1,1-Δx,Δx}]

out=DynamicModule[{n=2},{
Manipulator[Dynamic[n],{2,(2^8),2}],
Dynamic[StringForm["Right Riemann sum area: ``",N[Sum[g[-1+i*(2/n)](2/n),{i,0,n-1}]]]],
Dynamic[Show[Plot[(x^2),{x,-1,1}],DiscretePlot[g[t],{t,-1+(2/n),1,(2/n)},ExtentSize->Left,PlotMarkers->"Point"]]],Dynamic[StringForm["Left Riemann sum area: ``",N[Sum[g[-1+i*(2/n)](2/n),{i,1,n}]]]],
Dynamic[Show[Plot[(x^2),{x,-1,1}],DiscretePlot[g[t],{t,-1,1-(2/n),(2/n)},ExtentSize->Right,PlotMarkers->"Point"]]]
}][[2]];
out[[1]]
out[[2]]
out[[3]]
out[[4]]
out[[5]]

(*Fibonacci # problem*)

(*Standard: the first and second Fibonacci numbers are 1 and 1*)
index=1;
fib={1,1}; (*fib = {(Subscript[F, n-1]),(Subscript[F, n])}*)
ans=0;
While[fib[[2]]<4000000,
temp=fib[[1]];
fib[[1]]=fib[[2]];(*(Subscript[F, n-1]) is replaced by (Subscript[F, n])*)
fib[[2]]+=temp;(*(Subscript[F, n]) is replaced by (Subscript[F, n+1])=(Subscript[F, n])+(Subscript[F, n-1])*)
If[Mod[fib[[1]],2]==0,ans+=fib[[1]]] ;(*accumulate even Fibonacci numbers*)
index++;
]
StringForm["The ``rd Fibonacci number, ``, is the largest one less than 4,000,000", index, fib[[1]]]
StringForm["The sum of all even Fibonacci numbers up to (Subscript[F, ``]) is ``", index, ans]