Can't integrate exponential function
Afficher commentaires plus anciens
I am trying to figure out how to write integral functions that have exponential numbers in the functions.
Matlab gives me an error for the following function:
%Practice integral with exponent
clc
clear
syms x
myFunc = @(x) (exp(x)/x);
y = integral(myFunc,3.5,4.5);
1 commentaire
Gabriel Sharp
le 11 Fév 2022
Réponse acceptée
Plus de réponses (2)
Telling integral() that the function is array-valued seems to work ok:
myFunc = @(x) (exp(x)/x);
y = integral(myFunc,3.5,4.5,'ArrayValued',true)
2 commentaires
Yes, but less efficiently. The integral computation will not be vectorized.
wp=linspace(3.5,4.5,1e5);
myFunc = @(x) (exp(x)/x);
tic;
y = integral(myFunc,3.5,4.5,'ArrayValued',true,'WayPoints',wp);
toc
myFunc = @(x) (exp(x)./x);
tic;
y = integral(myFunc,3.5,4.5,'WayPoints',wp);
toc
Voss
le 11 Fév 2022
syms x
myFunc = (exp(x)/x);
tic; y1 = int(myFunc,3.5,4.5), double(y1), toc
tic; y2 = vpaintegral(myFunc,3.5,4.5), double(y2), toc
1 commentaire
Gabriel Sharp
le 11 Fév 2022
Catégories
En savoir plus sur Code Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!