How do I plot a univariate integral?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tatte Berklee
le 4 Août 2020
Réponse apportée : Alan Stevens
le 7 Août 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?!
0 commentaires
Réponse acceptée
Alan Stevens
le 7 Août 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')
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!