How do I plot a univariate integral?

1 次查看(过去 30 天)
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?!

采纳的回答

Alan Stevens
Alan Stevens 2020-8-7
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')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by