Plotting Area of a function

2 次查看(过去 30 天)
Hello,
I have this function:
fun = @(x) (x^2 + 2)
q=int(fun,x,[-1,2])
q=9
How do i plot this fun function with the shaddes are betweeen -1, 2 of the integral?
Thanks

采纳的回答

Star Strider
Star Strider 2021-3-30
I am not sure what you want.
Try this:
fun = @(x) (x.^2 + 2)
q = integral(fun,-1,2)
xv = linspace(-2,3);
xseg = xv(xv>=-1 & xv<=2);
figure
plot(xv, fun(xv))
hold on
patch([xseg fliplr(xseg)], [fun(xseg) zeros(size(xseg))], 'b', 'FaceAlpha',0.25)
hold off
text(mean(xseg), q*0.1, sprintf('$\\int_{%d}^{%d}x^2+2 dx = %d$',-1,2,q), 'Horiz','center', 'Vert','middle', 'Interpreter','latex')
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by