Undefined variable in a self-written function

Hello everyone,
I am facing a probelm, below is the codes of the function.
function para = MH(para, x)
A = para(1);
mu = para(2);
Ms = para(3);
sigma = para(4);
C = para(5);
kb=1.38065e-23;
T=295;
distribution = @(d) exp(-(log(d/mu).^2/(2*sigma^2)))./(d*sigma*sqrt((2*pi)));
langevin = @(d) coth((d.^3*pi./6*Ms.*x)/(kb*T))-(kb*T)./(pi./6*Ms.*x.*d.^3);
integrand = langevin(d).*distribution(d).*(pi/6)*d.^3;
para = A*integral(@(d) integrand,0,200e-9)+C.*x;
end
When the whole program ran, the erro code says the 'd' is undefined. d is the variable of integration whose limit of integration is (0,200e-9), how should I define 'd' in this situation? This is my first time using 'integral' function.
When it's prossible, may I ask another question? I am trying to fit a M(H) curve, the formulation is:
where
,
the unknown parameters are A, Ms, Sigma, Mu and C.
The dimension of variable x is (61×1).
The problem is, I once successed running the program (by giving d a arbitrary value in this function), but the part 'intergrand' doesn't be integrated at all, the returned parameter Ms, Sigma and Mu doesn't change, only A and C changed, may I ask what's the reason for that? Thanks for any help in advance!

답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 17일

0 개 추천

integrand = @(d) langevin(d).*distribution(d).*(pi/6)*d.^3;
para = A*integral(integrand,0,200e-9)+C.*x;

댓글 수: 2

Zhao
Zhao 2021년 6월 17일
Hello,
thank you so much for your advice! Ya, it runs without the former erro codes now, the current problem is that the term integrand doesn't be integrated, the operand is only C*x. The result is below:
Do you have any idea about this problem? Thank you so much for your help!
You are integrating over a fairly small area, 0 to 200e-9 . My guess is that the integral is coming out as nearly 0 compared to C.*x

댓글을 달려면 로그인하십시오.

질문:

2021년 6월 17일

댓글:

2021년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by