Error message when computing integral: first input argument must be a function handle
165 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Josh Meyer
on 13 Sep 2017
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)
More Answers (1)
Ayatullah
on 13 Oct 2022
Edited: Ayatullah
on 13 Oct 2022
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!