Error message when computing integral: first input argument must be a function handle

조회 수: 172 (최근 30일)
I'm trying to evaluate this integral, but when I enter this code:
syms x;
S= (6*(sin(x)^2)/(3*sin(x)+1));
l= integral(S,0,pi)
it gives me the error message: Error using integral, first input argument must be a function handle.
I'm a beginner Matlab user, so the answer is probably pretty straightforward, but any help is appreciated, thanks in advance!

채택된 답변

Josh Meyer
Josh Meyer 2017년 9월 13일
If you want to compute the integral symbolically by keeping the line "syms x;", then you'll need to use the function in Symbolic Math Toolbox for integrating: int.
In that case the code looks like this:
syms x
S = (6*(sin(x)^2)/(3*sin(x)+1));
l = int(S,x,0,pi)
An alternate way to do this is to continue using the integral function. In that case you don't need the line "syms x", since integral integrates function handles. Function handles look like a normal line of code, but the beginning of the line defines the variables in the expression using the @ symbol. In this case the code looks like:
S = @(x) (6*(sin(x).^2)./(3*sin(x)+1));
l = integral(S,0,pi)
(Note the subtle use of element-wise operations .^ and ./ in this second case)

추가 답변 (1개)

Ayatullah
Ayatullah 2022년 10월 13일
편집: Ayatullah 2022년 10월 13일
n =0:0.5:10;
x = exp(-1*n);
subplot(3,3,1),stem(x)
title('exponential')
g = sin(n);
subplot(3,3,2),stem(g)
title('sinusoidal')
y =integral ((exp(-1*n).*sin(n)) ,0,n)
subplot(3,3,3), stem(y)
title('convolution')
i am dealing with this code but i am getting this error(Error using integral
First input argument must be a function handle.
Error in convolution (line 11)
y =integral ((exp(-1*n).*sin(n)) ,0,n))
can anyone help me with it

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by