Exercises 2-3. Functions and Their Graphs. 
Calculus - Limits and Derivatives.

Defining functions. Plotting graphs.

f[x_]:=x^2
Plot[f[x],{x,-10,10}]
Plot[f[x],{x,5,6}]

Piecewise

f[x_]:=({{\[Piecewise], ({{x, 0≤x≤1}, {-x, -1<x<0}, {1, x≤-1||x>1}})}})
Plot[f[x],{x,-3,3}]

f[x_]:=({{\[Piecewise], ({{x, 0≤x≤1}, {-x, -1<x<0}, {1, True}})}})
Plot[f[x],{x,-3,3}]

Exclusions

f[x_]:=(((x^5)-4(x^2)+1)/(x-(1/2)))
Plot[f[x],{x,-3,3}]
Plot[f[x],{x,-10,10}]

Plot[f[x],{x,-3,3},Exclusions->{1/2}]

Plot[({{\[Piecewise], ({{1, x≥1}, {-1, x<1}})}}),{x,-3,3},ExclusionsStyle->Dashed]

Plot Options

PlotRange

f[x_]:=100Cos[x]+(E^(x^2))
GraphicsRow[{Plot[f[x],{x,-3,3}],
Plot[f[x],{x,-3,3},PlotRange->All],
Plot[f[x],{x,-3,3},PlotRange->{0,250}]}]

AspectRatio

GraphicsRow[{Plot[2(((x-4))^2)+1,{x,3,5}],
Plot[2(((x-4))^2)+1,{x,3,5},AspectRatio->Automatic],
Plot[2(((x-4))^2)+1,{x,3,5},AspectRatio->0.5]}]

Plot[f[x],{x,-3,3},PlotRange->{0,250},AspectRatio->Automatic]

AxesOrigin

Plot[2(((x-4))^2)+1,{x,3,5},AxesOrigin->{0,0}]

Style

GraphicsRow[{Plot[2(((x-4))^2)+1,{x,3,5},PlotStyle->Red],
Plot[2(((x-4))^2)+1,{x,3,5},PlotStyle->Dashed],
Plot[2(((x-4))^2)+1,{x,3,5},PlotStyle->Directive[Dashed,Red,Thick]],
Plot[2(((x-4))^2)+1,{x,3,5},PlotStyle->Directive[Orange,Thickness[0.025]]],
Plot[2(((x-4))^2)+1,{x,3,5},PlotStyle->Directive[Dotted,Gray]]}
]

Exercise 1: In a certain country, income tax is assessed as follows. There is no tax on income up to $10,000. Any income over $10,000 is
taxed at a rate of 10%, up to an income of $20,000. Any income over $20,000 is taxed at 15%.
In one row:
(a) Plot the graph of the tax rate R as a function of the income I.
(b) Plot the graph of the total assessed tax T as a function of the income I.
Insert appropriate captions of the figures and axes labels. Format the graph such that it is clearly visible.

R[x_]:=({{\[Piecewise], ({{0, x≤10000}, {10, 10000<x≤20000}, {15, True}})}})
GraphicsRow[{Plot[R[x],{x,0,30000},Exclusions->{10000,20000},ExclusionsStyle->Dashed,PlotStyle->Thickness[0.015],PlotLabel->"Tax Rate", AxesLabel->{"I","R(I)"}],
Plot[((R[x])/100)x,{x,0,30000},Exclusions->{10000,20000},ExclusionsStyle->Dashed,PlotStyle->Thickness[0.015],PlotLabel->"Assessed Tax", AxesLabel->{"I","T(I)"}]}]

Exercise 2: Given the graph of y=(Sqrt[x]), plot the graphs of y=(Sqrt[x])-2, y=(Sqrt[x-2]), y=-(Sqrt[x]), y=(Sqrt[-x]). Plot the original function with a thick red line. Insert axes labels and a legend.
How does the graph of the original function change under those transformations?

Plot[{(Sqrt[x]),(Sqrt[x])-2,(Sqrt[x-2]),-(Sqrt[x]),(Sqrt[-x])},{x,-20,20},PlotLegends->{"(Sqrt[x])","(Sqrt[x])-2","(Sqrt[x - 2])","-(Sqrt[x])","(Sqrt[-x])"},
PlotStyle->{Directive[Thickness[0.015],Red],Automatic,Automatic,Automatic,Automatic, Automatic},AxesLabel->{"x","y"}]

Exercise 3: A variable star is one whose brightness alternately increases and decreases. For the most visible variable star, Delta Cephei, the time between periods of maximum brightness
is 5.4 days, the average brightness of the star is 4.0, and its brightness varies by ±0.35 magnitude. Find a function that models the brightness of Delta Cephei as a function of time.

B[t_]:=4+0.35Sin[((2Pi)/5.4)t]
Plot[{B[t],4,4.35,3.65},{t,0,20},PlotStyle->{Blue, Directive[Gray, Dashed], Directive[Gray, Dashed], Directive[Gray, Dashed]},AxesLabel->{"t","B(t)"},PlotLabel->"Delta Cephei Brightness"]

Exercise 4: The curves with equations
y=((|x|)/(Sqrt[c-(x^2)]))
are called bullet-nose curves. 
(a) Graph some of these curves to see why. 
(b) Use the Manipulate function to study what happens with the function as c increases.

f[x_,c_]:=((Abs[x])/(Sqrt[c-(x^2)]))
Manipulate[Plot[f[x,c],{x,-2,2},AspectRatio->Automatic, PlotRange->{0,4}],{c,1,100,0.5}]

Derivatives

Exercise 5 : Let us consider the function f(x):=-(x^4)+2x. Let (Subscript[x, 0])=1. Using the Manipulate function show that the secant line
through the points ((Subscript[x, 0]), f((Subscript[x, 0]))), (((Subscript[x, 0])+Δx, f((Subscript[x, 0])+Δx))) tends to the line, tangent to f(x) at ((Subscript[x, 0]), f((Subscript[x, 0]))) as Δx→0.

f[x_]:=-x^4+2x
x0=1;
Manipulate[Plot[{f[x],f'[x0]x+f[x0]-f'[x0],((f[x0+Δx]-f[x0])/(Δx))(x-x0)+f[x0]},{x,-1,2},PlotRange->{-15,10},PlotLegends->{"f(x)","Tangent","Secant"},PlotStyle->{Thickness[0.01], Automatic, Automatic}],{Δx,1,0.0001}]

Exercise 6 : Let us consider the function f(x):=sin x. Using the Manipulate function show that the difference quotient
g(x):=((f(x+Δx)-f(x))/(Δx)) tends to (df/dx)as Δx→0. 
Plot f(x) and g(x) in one coordinate system alongside with the absolute error |f(x)-g(x)|.

f[x_]:=Sin[x]
fDiffQuot[x_,Δx_]:=((f[x+Δx]-f[x])/(Δx))
Manipulate[GraphicsRow[{Plot[{fDiffQuot[x,Δx],f'[x]},{x,-2Pi,2Pi},PlotLegends->{"((f (x + Δx) - f (x))/(Δx))","f'(x)"}],
Plot[{Abs[fDiffQuot[x,Δx]-f'[x]]},{x,-2Pi,2Pi},PlotLabel->"AbsoluteError",PlotRange->{0,0.4}]}],{Δx,1,0.0001}]

Exercise 7: A cardiac monitor is used to measure the heart rate of a patient after surgery.
It compiles the number of heartbeats after t minutes. 
({{t, min, 36, 38, 40, 42, 44}, {Heartbeats, 2530, 2661, 2806, 2948, 3080}})
Estimate the heart rate of the patient.

data={{36,2530},{38,2661},{40,2806},{42,2948},{44,3080}};
plot1=ListPlot[data,PlotMarkers->●]

p[x_]=Fit[data,{1,x},x]
Show[Plot[p[x],{x,36,44},AxesLabel->{"t,min", "Heartbeats"},PlotLabel->"Cardiac Monitor Data"],
plot1]
Print["The average heart rate of the patient is ", p'[x], " bpm"]

Exercise 8: Define a function taylorPoly[f_,n_,x0_] that finds the Taylor polynomial of degree n for the function f around x0.

taylorPoly[f_,n_,x0_]:=(∑_(i=0)^n)((D[f[x],{x,i}]/.{x->x0})/(i!))(((x-x0))^i)
f[x_]:=(E^x)
p2[x_]=taylorPoly[f,2,0];
p3[x_]=taylorPoly[f,3,0];
p4[x_]=taylorPoly[f,4,0];
p5[x_]=taylorPoly[f,5,0];
p6[x_]=taylorPoly[f,6,0];

GraphicsRow[{Plot[{f[x],p2[x]},{x,-3,3}],
Plot[{f[x],p3[x]},{x,-3,3}],
Plot[{f[x],p4[x]},{x,-3,3}],
Plot[{f[x],p5[x]},{x,-3,3}],
Plot[{f[x],p6[x]},{x,-3,3}]}]