How do I plot a univariate integral?

1 visualización (últimos 30 días)
Tatte Berklee
Tatte Berklee el 4 de Ag. de 2020
Respondida: Alan Stevens el 7 de Ag. de 2020
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?!

Respuesta aceptada

Alan Stevens
Alan Stevens el 7 de Ag. de 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')

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by