Error message when computing integral: first input argument must be a function handle
173 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James Robinson
el 13 de Sept. de 2017
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 comentarios
Respuesta aceptada
Josh Meyer
el 13 de Sept. de 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)
2 comentarios
Más respuestas (1)
Ayatullah
el 13 de Oct. de 2022
Editada: Ayatullah
el 13 de Oct. de 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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!