How do I plot a univariate integral?

1 view (last 30 days)
I am the following code, and I am trying to PLOT below integral over some positive real numbers's range x:
[p,S] = polyfit(x, y, 6);
fun = @(x) x/(p(1,1)*x.^6+p(1,2)*x.^5+p(1,3)*x.^4+p(1,4)*x.^3+p(1,5)*x.^2+p(1,6)*x+p(1,7)).^2;
exp = integral(fun,0,Inf,'ArrayValued',true);
Is there away I can plot the function, FUN, and with the integration?
I looked at cumtrapz, but I don't understand how it would work with a univariate integral case?
Can someone help?!

Accepted Answer

Alan Stevens
Alan Stevens on 7 Aug 2020
Like this (you will need to replace my arbitrary polynomial with your own):
% Arbitrary polynomial
p = [2 1 -1 3 1 -1 5];
fun = @(x) x./(p(1,1)*x.^6+p(1,2)*x.^5+p(1,3)*x.^4+p(1,4)*x.^3+p(1,5)*x.^2+p(1,6)*x+p(1,7)).^2;
x = 0:0.01:2;
y = fun(x);
yint = zeros(size(x));
for i = 1:length(x)
yint(i) = integral(fun,0,x(i),'ArrayValued',true);
end
plot(x,y,x,yint)
xlabel('x'),ylabel('y')
legend('function','integral')

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!