First input argument must be a function handle.

Hi, I am trying to integrate using the following function:
if true
syms h g x pi
h = 2.0545
g = 5.3442
C = 1
y = C - (exp(-2.*g.*i.*x./h)).*(C - cos(x).*((h.^2)./2) + (g.*x)/2.*h.*i)
yx = integral(y,-pi,pi)
end
however, I get the error "First input argument must be a function handle. "
Can anyone suggest a solution?
Thanks!

 Réponse acceptée

KSSV
KSSV le 10 Août 2017
h = 2.0545 ;
g = 5.3442 ;
C = 1 ;
y = @(x) C - (exp(-2.*g.*1i.*x./h)).*(C - cos(x).*((h.^2)./2) + (g.*x)/2.*h.*1i) ;
yx = integral(y,-pi,pi)

3 commentaires

Sergio Manzetti
Sergio Manzetti le 10 Août 2017
Modifié(e) : Sergio Manzetti le 10 Août 2017
Hi KSSV, tried your suggestion on a full model:
if true
syms h g x C
h = 1.0545;
g = 5.34428;
C = 40;
a = (C - (exp(-2.*g.*i.*x./h)).*(C);
b = (C - (exp(-2.*g.*-i.*x./h)).*(C);
y = @(x) a*b;
q = integral(y,10^-9,0);
end
but it gives:
Error in integral (line 88) Q = integralCalc(fun,a,b,opstruct);
y = @(x) ((C - (exp(-2.*g.*i.*x./h)).*C) * ((C - (exp(-2.*g.*-i.*x./h)).*C);
In your anonymous function the @(x) is not the symbolic variable x.
Thanks. It must have function and not a result or call to another function in other words..?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by