Can't integrate exponential function
显示 更早的评论
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);
采纳的回答
更多回答(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 个评论
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
2022-2-11
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
类别
在 帮助中心 和 File Exchange 中查找有关 Code Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!