(*Video 1: Fundamental Theorem of Calculus *)

(*Antiderivative of x^2, also known as indefinite integral of x^2 *)
HoldForm[Integrate[x^2,x]]==Integrate[x^2,x]

(*Definite integral of x^2, from x=a to x=b*)
HoldForm[Integrate[x^2,{x,a,b}]]

F[t_]:=t^3/3

(*The above definite integral, by definition, is the area under the graph of y=x^2 that lies between x=a and x=b*)

Manipulate[Grid[{{Row[{"Area under graph of y=f(x) from a=",a," to b=",b," is ",F[b]-F[a]}]},{Row[{"Value of F(",b,")-F(",a,")=",F[b]-F[a]}]},{Show[Plot[x^2,{x,0,5},ImageSize->500],Plot[x^2,{x,a,b},Filling->Bottom,PlotRange->{{0,5},{0,25}},ImageSize->500]]}},Spacings->{1,1},Frame->All],{{a,2},0.01,5},{{b,4},0.02,5}]

(*Fundamental Theorem of Calculus:*)

(∫_a^b)f[t]\[DifferentialD]t=F[b]-F[a]

(*where F[x] is an antiderivative of f[x], i.e., F'[x]=f[x]. *)
(*Note: on the left we have a definite integral,
on the right we have the difference of values of a indefinite integral*)

(* Let's see that F[x] + C leads to the same result, that is, any antiderivative can be used:
*)

Integrate[x^2,x]

otherF[x_]:=F[x]+C
otherF[x]

Integrate[x^2,{x,1,2}]

F[2]
F[1]

F[2]-F[1] (*Computing the above definite integral using the FTC and antiderivative F*)

otherF[2]
otherF[1]

otherF[2]-otherF[1] (*Computing the above definite integral using the FTC and antiderivative otherF*)

(*Another example:*)
f[x_]:=x^3+2x^2-5x+6
Integrate[f[x],x](*Antiderivative / Indefinite integral*)

F[x_]:=6 x-((5 (x^2))/2)+((2 (x^3))/3)+((x^4)/4)+17

F'[x]==f[x]

(*Definite integral of f(x) from a=-2 to b=3 *)

Integrate[f[x],{x,-2,3}]

(*Difference of values of antiderivative F[b] - F[a] *)
F[3]-F[-2]

(*Define antiderivative / indefinite integral*)
F[x]=∫((x^3)+2 (x^2)-5 x+6)\[DifferentialD]x=6 x-((5 (x^2))/2)+((2 (x^3))/3)+((x^4)/4)+17

(*By the FTC, we know:*)

(∫_(-2)^3)((x^3)+2 (x^2)-5 x+6)\[DifferentialD]x=F[3]-F[-2]

(*Video 2: Another take on the Fundamental Theorem of Calculus*)

HoldForm[g[x]=Integrate[t^2,{t,0,x}]]

g[x_]:=Integrate[t^2,{t,0,x}]

g[4]

Plot[g[x],{x,-3,3}]

g'[t]

(*The FTC can also be stated as:*)

D[(∫_a^x)f[t]\[DifferentialD]t,x]=f[x]

Integrate[E^t+5t^2-6t+1,{t,0,x}]

g[x_]:=-1+(E^x)+x-3 (x^2)+((5 (x^3))/3)

g'[x]==E^t+5t^2-6t+1/.t->x

(*How about endpoints which are more complicated functions of x*)

g[x]=(∫_(2x+1)^(7x))f[t]\[DifferentialD]t

f[t]=5t+1

g[x_]:=Integrate[5t+1,{t,2x+1,7x}]

g'[x]

(*How do we compute that by hand?*)

(∫_(2x+1)^(7x))f[t]\[DifferentialD]t=(∫_a^(7x))f[t]\[DifferentialD]t-(∫_a^(2x+1))f[t]\[DifferentialD]t

g'[x]=D[(∫_(2x+1)^(7x))f[t]\[DifferentialD]t,x]=D[(∫_a^(7x))f[t]\[DifferentialD]t,x]-D[(∫_a^(2x+1))f[t]\[DifferentialD]t,x]

(*So compute each of the two derivatives on the right using the FTC and Chain rule*)

D[Integrate[5t+1,{t,a,7x}],x]-D[Integrate[5t+1,{t,a,2x+1}],x]

Simplify[5+5 (49 x-2 (1+2 x))==5+245 x-10 (1+2 x)]

(*Recall how the Chain rule is applied: we are composing two functions, the integral with endpoint y(x) and y(x)=7x*)

D[Integrate[5t+1,{t,a,y}],y](*Use FTC here!*)

1+5 y/.y->7x(*Replace y for what it is*)

D[7x,x](*Derivative of the inside function y(x)*)

Expand[(1+35 x)*7](*Chain rule: multiply the above to get answer*)

D[Integrate[5t+1,{t,a,7x}],x]

(*Similarly for the second one:*)

D[Integrate[5t+1,{t,a,2x+1}],x]

(*Then take the difference to find g' :*)

Simplify[g'[x]==D[Integrate[5t+1,{t,a,7x}],x]-D[Integrate[5t+1,{t,a,2x+1}],x]]