Plotting Area of a function

2 visualizaciones (últimos 30 días)
Rodrigo Toledo
Rodrigo Toledo el 30 de Mzo. de 2021
Comentada: Star Strider el 30 de Mzo. de 2021
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

Respuesta aceptada

Star Strider
Star Strider el 30 de Mzo. de 2021
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')
.
  2 comentarios
Rodrigo Toledo
Rodrigo Toledo el 30 de Mzo. de 2021
this is exactly what i needed. Thanks.
Star Strider
Star Strider el 30 de Mzo. de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by