Derivative of intergrated bessel function

Hi,
I'm trying to plot a curve determined by the first and second derivatives of an expression defined using besselj. The definitions of my derivatives and my function are below :
I've succeeded in defining the function as follow, using defined scalar for the integral :
Fhertz=@(r) P*l^2/(2*pi*D)*integral(@(m) besselj(0,m.*r/l).*m./(1+m.^4),0,1000)
But now I'm trapped as I can't find a way to calculate the 2 M as defined above, Matlab seems not to accept my function when I try to use the diff function :
Mr1= @(r)-D*(1/r*diff(Fhertz)+nu/r*diff(Fhertz,2))
fplot(Mr1, [0 10*l]);
Undefined function 'diff' for input arguments of type 'function_handle'.
Error in @(r)-D*(1/r*diff(Fhertz)+nu/r*diff(Fhertz,2))
Error in fplot>splitFunctionHandle (line 255) fnAtZero = fn(0);
Error in fplot (line 119) fn{1} = splitFunctionHandle(fn{1});
Thanks in advance for your help

Réponses (1)

Steven Lord
Steven Lord le 21 Sep 2016
You can't do math on function handles. You can do math on the values returned by function handles.
s = @sin;
c = @cos;
tNO = @(x) s./c % will not work if you try to evaluate tNO
tYES = @(x) s(x)./c(x) % will work
v = -pi:0.1:pi;
tYES(v)-tan(v) % all elements should be small
See the example "Approximate Derivatives with diff" on the documentation page for diff for how to use it to approximate a function's derivative.

2 commentaires

Thanks for the answer !
I've tried defining it as you suggested, but it doesn't work either. If I just define the function as depending on r I get :
Mr1= @(r)-D*(1/r.*diff(Fhertz(r))+nu./r*diff(Fhertz(r),2));
>> Mr1(8);
>> Mr1(8);
>> Mr1(8)
ans = []
So obviouvsly the function is not working.
If I try the method defined in the documentation pages, I can't even define the function :
h = 0.001; % step size
r = 0:h:10*l; % domain
f = Fhertz(r); % range
Y = diff(f)/h; % first derivative
Z = diff(Y)/h; % second derivative
A = @(r)-D*(1/r.*Y+nu./r*Z);
Matrix dimensions must agree.
Error in @(m)besselj(0,m.*r/l).*m./(1+m.^4)
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in @(r)P*l^2/(2*pi*D)*integral(@(m)besselj(0,m.*r/l).*m./(1+m.^4),0,1000)true
So I'm still stuck...
Steven Lord
Steven Lord le 21 Sep 2016
If you call the diff function with a nonempty vector as input, the output vector has one fewer element than the input. You need to adjust for that.
Alternately, you may find the gradient function useful.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by