Can't integrate exponential function
Mostrar comentarios más antiguos
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 comentario
Gabriel Sharp
el 11 de Feb. de 2022
Respuesta aceptada
Más respuestas (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 comentarios
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
el 11 de Feb. de 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 comentario
Gabriel Sharp
el 11 de Feb. de 2022
Categorías
Más información sobre Code Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!