1
$\begingroup$
  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

$\endgroup$
2
  • 1
    $\begingroup$ try Show? See also the examples in ExtentSize $\endgroup$
    – kglr
    Commented Jan 15, 2022 at 18:54
  • $\begingroup$ Related 19542 $\endgroup$
    – Edmund
    Commented Jan 15, 2022 at 19:52

1 Answer 1

3
$\begingroup$
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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.