How can I plot the answer of an integral Vs. its variable upper limit?

7 views (last 30 days)
For example y=integral((1+x^2)*exp(-x),0,z), (this is just an example and my integral is not this case), and the lower limit of integral is zero and the upper limit (z) varies from 0 to for example 10. Then I want to plot the (z,y) curve.

Answers (1)

Star Strider
Star Strider on 24 Oct 2015
Using your ‘hypothetical’ function, if it is similar to the function you actually want to integrate, this works:
z = linspace(0, 10, 25);
for k1 = 1:length(z)
y(k1) = integral(@(x)(1+x.^2).*exp(-x),0,z(k1));
end
figure(1)
plot(z, y)
xlabel('z')
ylabel('\int(1+x^{2})\cdote^{-x}\it{dx}\rm')
Make appropriate changes to get the result you want with your actual function. (You can get better axis labels using LaTeX rather than TeX in this instance, but this will work for the example here.)

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!