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!