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

163 次查看(过去 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

Community Treasure Hunt

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

Start Hunting!

Translated by