1
  1. Using Mathematica create a single graph that plots both the function

a)$f(x)=\sqrt(x+4)$ on the domain $-4\leq x \leq4$

b) A visualization of a left-hand Riemann sum with 10 rectangles

Here is my code so far:

a=-4;
b=4;
n=10;
DX=(b-a)/n;
f[x_]:=Sqrt[x+4];
DiscretePlot[{f[x]},{x,-4,4,(4/5)}]
Plot[f[x],{x,-4,4}]

enter image description here

enter image description here

What I want to do is to plot on one single graph, the function f(x) and my 10 rectangles. I do not know what functions to use. Thank you

J F
  • 63
  • 3

1 Answers1

3
a = -4;
b = 4;
n = 10;
DX = (b - a)/n;
f[x_] := Sqrt[x + 4];

Show[
 DiscretePlot[{f[x]}, {x, -4, 4, (4/5)}, ExtentSize -> Right],
 Plot[f[x], {x, -4, 4},
  PlotStyle -> ColorData[97][2]],
 PlotRange -> {{-4, 4}, Automatic},
 PlotRangePadding -> 0]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198