Undefined function 'matlabFunction' for input arguments of type 'function_handle'.

4 views (last 30 days)
Hello everyone, I have problem about integrate function and convert the sym to number...the following is my code
it always shows
"Undefined function ' *matlabFunction*' for input arguments of type 'function_handle'."..
I am not sure whether I could use 'matlabFunction' or not.. thank you for your help:)
ka = 1.38e-23; % Boltzmann constant, unit m^2*kg*s^(-2)*K^(-1)
T = 273+25; % Room temperature, where experiments were conducted, unit K
u_0 = pi*4e-7; % Permeability of free space, unit Henry/m
d_pb = 11e-9; % mean magnetic nanoparticle diameter in microbeads
d_pm=9.9e-9;% median magnetic nanoparticle diameter in microbeads (must use nm unit)
M_db = 370e+3; % Magnetic nanoparticle bulk magnetization
H=1.45/u_0; %T magnetic flux density
HG =20 ; %T/m field gradient
alpha=u_0*pi*d_pb^3*M_db*H/6/ka/T;
Lang=coth(alpha)-1/alpha;
% Fm=u_0*pi*d_pb^3/6*M_db*Lang*HG;
syms D %polydisperse
lamda_P=6*ka*T/pi./D.^3./M_db/Lang/HG;
Fm_P=u_0*pi.*D.^3./6*M_db*Lang*HG;
u=1/3/pi/eta_f./D; % mobility given by the sokes formula
D_0=u*ka*T;
A=u.*Fm_P;
s =0.6; % poly dispersity index
beta = (log(1+s^2))^0.5;
w= 1200e-6; % channel width
l=lamda_P;
n0 =3e16;
Z=linspace(0,1200,5);
T=linspace(1e5,1e5,1);
syms k
for i = 1:length(T)
t=T(i);
for j = 1:length(Z)
z=Z(j)*1e-6;
KV=(k^2*(1-(-1)^k*exp(w/2./l))/(pi^2*k^2+ w^2/4./l.^2)^2*(cos(pi*k*z/w)-w/2/pi/k./l.*sin(pi*k*z/w))*exp(-1*(pi^2*k^2+w^2/4./l.^2)*D_0*t/w^2));
fun1_1 = @(D)(n0*w*exp(-z./l)./l./(1-exp(-w./l))-2*pi^2*n0*w./l.*exp(-z/2/l).*double(symsum(KV,k,1,1e3))).*exp(-(log(D./d_pm)).^2./2./beta^2)./beta./D./(2*pi)^0.5; % number concentration distribution
fun1fcn=matlabFunction(fun1_1);
N_zt(i,j)=integral(fun1fcn,0,Inf)
end
end
plot(Z,N_zt)

Answers (1)

Walter Roberson
Walter Roberson on 7 Jul 2018
Remove the @(D) from the definition of fun1_1
  2 Comments
Yang Liu
Yang Liu on 7 Jul 2018
Edited: Walter Roberson on 7 Jul 2018
thank you for your response. matlab could process the code now. but the result is NaN.
my revised code is:
fun1_1 =(n0*w*exp(-z./l)./l./(1-exp(-w./l))-2*pi^2*n0*w./l.*exp(-z/2./l).*symsum(KV,k,1,1e3)).*exp(-(log(D./d_pm)).^2./2./beta/beta)./beta./D./(2*pi)^0.5
fun1fcn=matlabFunction(fun1_1);
N_zt(i,j)=vpa(integral(fun1fcn,0,Inf))
I am totally confused now...sign..
Walter Roberson
Walter Roberson on 7 Jul 2018
You should not go back and forth between symbolic and numeric. If you want to end up with symbolic you should use
fun1_1 = ... etc
N_zt(i, j) = vpaintegral(fun1_1, D, 0, Inf);
However this will still have problems.
Your fun1_1 multiplies and divides by D in a number of places, so at your starting point of 0, any numeric evaluation is going to end up with places in the code with division by 0, or with 0 / 0 . The meaning of the integral at 0 therefore has to involve careful evaluation of limits. Unfortunately calculating the limit at 0 turns out to be fairly time consuming; I am not sure how many hours it will take to compute it.

Sign in to comment.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!