Azzera filtri
Azzera filtri

Undefined variable in a self-written function

1 visualizzazione (ultimi 30 giorni)
Zhao
Zhao il 17 Giu 2021
Commentato: Walter Roberson il 19 Giu 2021
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!

Risposte (1)

Walter Roberson
Walter Roberson il 17 Giu 2021
integrand = @(d) langevin(d).*distribution(d).*(pi/6)*d.^3;
para = A*integral(integrand,0,200e-9)+C.*x;
  2 Commenti
Zhao
Zhao il 17 Giu 2021
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!
Walter Roberson
Walter Roberson il 19 Giu 2021
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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by