How to avoid the overshoot in Jiles Atherton hysteresis loop
Show older comments
Trying to plot a hysteresis model using jiles atherton hysteresis model in matlab. All the parameters are defined in the beginning.
Here is the code I have written,
clear
%% Given parameters
a = 512;
c = 0.75;
k = 570;
M_s = 1.7*10^6;
i_s = 10^-6;
alpha = 0.032;
u_0 = 4*pi*10^-7;
f = 1;
h_max = 8000;
%% Generate time vector
t_start = 0; %start time
t_end = 60; %end time
dt = 0.001; %time steps
t = t_start:dt:t_end;
%% Initial values
M_irev(1) = 0; %Initial irreversible magnetization
h = h_max*sin(2*pi*f*t); % Sinusoidal magnetic field strength
%% Time stepping loop
for i=2:length(t)
% Compute effective field
h_e = h(i); % Applied field and effective field considered equal
% Compute anhysteric magnetization
M_an = M_s*(coth(h_e/a) - (a/(h_e))); % Langevin function
% Compute derivative of magnetic field with respect to time
dh_e = (h(i) - h(i-1)) / dt;
delta = sign(dh_e);
% Compute irreversible magnetization using Euler method
M_irev(i) = ((M_an - M_irev(i-1)) / ((k * delta) - (alpha * (M_an - M_irev(i-1))))) * dh_e;
% Update magnetization
M(i) = c*M_an + (1-c)*M_irev(i);
end
%% Magnetic flux density
B = u_0 * (h + M);
%% Plot results
figure;
plot(h, B);
xlabel('Magnetic Field Strength');
ylabel('Magnetic Flux Density');
title('HB Graph');
grid on;
The problem I am facing is when it plots the curve, it shows overshoot at three points. Suspecting the problem is in the 'Langevin function'. Lower values of h at the end part creates bigger values thus it shows overshoot at those points. I think I need to use approximation (Taylor series or similar method) at those points so that when overshoot happens the code will avoid those overshoots and take the approximation. Can anyone show me how can I do that approximation?
1 Comment
Josefina
on 20 Nov 2025
Read the recent work: "Blind Efficient Method for Optimizing Jiles-Atherton Model Parameters", TMAG, (2025). The study provides a detailed decription the the implementation of the JA model in MATLAB, together with a novel fast and blind method for retrieving the 5 standard model parameters for a given material.
You may contact the corresponding author for any help or collaboration.
Answers (1)
hello
I am just trying to remove the spikes (with filloutiers) and further smooth the curve with a touch of smoothdata
look at these 2 lines I added at the plot section
Bs= filloutliers(B,'linear','movmedian',15, 'ThresholdFactor', 1.1);
Bs= smoothdata(Bs,'sgolay',50);
code :
clear
%% Given parameters
a = 512;
c = 0.75;
k = 570;
M_s = 1.7*10^6;
i_s = 10^-6;
alpha = 0.032;
u_0 = 4*pi*10^-7;
f = 1;
h_max = 8000;
%% Generate time vector
t_start = 0; %start time
t_end = 60; %end time
dt = 0.001; %time steps
t = t_start:dt:t_end;
%% Initial values
M_irev(1) = 0; %Initial irreversible magnetization
h = h_max*sin(2*pi*f*t); % Sinusoidal magnetic field strength
%% Time stepping loop
for i=2:length(t)
% Compute effective field
h_e = h(i); % Applied field and effective field considered equal
% Compute anhysteric magnetization
M_an = M_s*(coth(h_e/a) - (a/(h_e))); % Langevin function
% Compute derivative of magnetic field with respect to time
dh_e = (h(i) - h(i-1)) / dt;
delta = sign(dh_e);
% Compute irreversible magnetization using Euler method
M_irev(i) = ((M_an - M_irev(i-1)) / ((k * delta) - (alpha * (M_an - M_irev(i-1))))) * dh_e;
% Update magnetization
M(i) = c*M_an + (1-c)*M_irev(i);
end
%% Magnetic flux density
B = u_0 * (h + M);
%% Plot results
figure;
Bs= filloutliers(B,'linear','movmedian',15, 'ThresholdFactor', 1.1);
Bs= smoothdata(Bs,'sgolay',50);
plot(h, B, h, Bs);
xlabel('Magnetic Field Strength');
ylabel('Magnetic Flux Density');
title('HB Graph');
grid on;
7 Comments
we could also do a cycle by cycle averaging and get the one cycle averaged curve , but at the end the result may look quite the same (almost , stil there is a small discontinuity, we can put a bit of smoothing there)
for the time being, this is the result without smoothing :
%% Given parameters
a = 512;
c = 0.75;
k = 570;
M_s = 1.7*10^6;
i_s = 10^-6;
alpha = 0.032;
u_0 = 4*pi*10^-7;
f = 1;
h_max = 8000;
%% Generate time vector
t_start = 0; %start time
t_end = 60; %end time
dt = 0.001; %time steps
t = t_start:dt:t_end;
%% Initial values
M_irev(1) = 0; %Initial irreversible magnetization
h = h_max*sin(2*pi*f*t); % Sinusoidal magnetic field strength
%% Time stepping loop
for i=2:length(t)
% Compute effective field
h_e = h(i); % Applied field and effective field considered equal
% Compute anhysteric magnetization
M_an = M_s*(coth(h_e/a) - (a/(h_e))); % Langevin function
% Compute derivative of magnetic field with respect to time
dh_e = (h(i) - h(i-1)) / dt;
delta = sign(dh_e);
% Compute irreversible magnetization using Euler method
M_irev(i) = ((M_an - M_irev(i-1)) / ((k * delta) - (alpha * (M_an - M_irev(i-1))))) * dh_e;
% Update magnetization
M(i) = c*M_an + (1-c)*M_irev(i);
end
%% Magnetic flux density
B = u_0 * (h + M);
%% cycle by cycle averaging
dtzc = 1/f;
tzc = t(1):dtzc:t(end);
NN = numel(tzc)-1;
hh = 0;
BB = 0;
for k = 1:NN
tstart = tzc(k);
tstop = tzc(k+1);
tt = linspace(tstart,tstop,360); % 360 => 1 degree resolution
hi = interp1(t,h,tt);
Bi = interp1(t,B,tt);
hh = hh + hi;
BB = BB + Bi;
end
% divide by N to obtain the averaged data
hh = hh/NN;
BB = BB/NN;
%% Plot results
figure;
plot(h, B, hh, BB);
xlabel('Magnetic Field Strength');
ylabel('Magnetic Flux Density');
title('HB Graph');
grid on;
just added now a bit of smoothing on top
see the effect here : smoothed curve is yellow

%% Given parameters
a = 512;
c = 0.75;
k = 570;
M_s = 1.7*10^6;
i_s = 10^-6;
alpha = 0.032;
u_0 = 4*pi*10^-7;
f = 1;
h_max = 8000;
%% Generate time vector
t_start = 0; %start time
t_end = 60; %end time
dt = 0.001; %time steps
t = t_start:dt:t_end;
%% Initial values
M_irev(1) = 0; %Initial irreversible magnetization
h = h_max*sin(2*pi*f*t); % Sinusoidal magnetic field strength
%% Time stepping loop
for i=2:length(t)
% Compute effective field
h_e = h(i); % Applied field and effective field considered equal
% Compute anhysteric magnetization
M_an = M_s*(coth(h_e/a) - (a/(h_e))); % Langevin function
% Compute derivative of magnetic field with respect to time
dh_e = (h(i) - h(i-1)) / dt;
delta = sign(dh_e);
% Compute irreversible magnetization using Euler method
M_irev(i) = ((M_an - M_irev(i-1)) / ((k * delta) - (alpha * (M_an - M_irev(i-1))))) * dh_e;
% Update magnetization
M(i) = c*M_an + (1-c)*M_irev(i);
end
%% Magnetic flux density
B = u_0 * (h + M);
%% cycle by cycle averaging
dtzc = 1/f;
tzc = t(1):dtzc:t(end);
NN = numel(tzc)-1;
hh = 0;
BB = 0;
for k = 1:NN
tstart = tzc(k);
tstop = tzc(k+1);
tt = linspace(tstart,tstop,360); % 360 => 1 degree resolution
hi = interp1(t,h,tt);
Bi = interp1(t,B,tt);
hh = hh + hi;
BB = BB + Bi;
end
% divide by N to obtain the averaged data
hh = hh/NN;
BB = BB/NN;
Bs= smoothdata(BB,'loess',20);
%% Plot results
figure;
plot(h, B, hh, BB, hh, Bs);
xlabel('Magnetic Field Strength');
ylabel('Magnetic Flux Density');
title('HB Graph');
grid on;
Mathieu NOE
on 30 Apr 2024
hello again
problem solved ?
Md Tanbir Siddik
on 4 May 2024
I am not sure it's the Langevin function which causes the issue
I traced down a few quantities (so I had to mdify a bit your code
if I plot Langevin function output (M_an), there is not much issue to be seen , except one single peak)
it seems to me there is a bigger issue in the Euler equation , if you trace down the numerator and denominator, it shows a lot of spikes , so there is some discontinuities in your process that must be corrected
%% Given parameters
a = 512;
c = 0.75;
k = 570;
M_s = 1.7*10^6;
i_s = 10^-6;
alpha = 0.032;
u_0 = 4*pi*10^-7;
f = 1;
h_max = 8000;
%% Generate time vector
t_start = 0; %start time
t_end = 60; %end time
dt = 0.001; %time steps
t = t_start:dt:t_end;
%% Initial values
M_irev(1) = 0; %Initial irreversible magnetization
h = h_max*sin(2*pi*f*t); % Sinusoidal magnetic field strength
%% Time stepping loop
for i=2:length(t)
% Compute effective field
h_e = h(i); % Applied field and effective field considered equal
% Compute anhysteric magnetization
M_an(i) = M_s*(coth(h_e/a) - (a/h_e)); % Langevin function
% Compute derivative of magnetic field with respect to time
dh_e(i) = (h(i) - h(i-1)) / dt;
delta(i) = sign(dh_e(i));
% Compute irreversible magnetization using Euler method
num(i) = (M_an(i) - M_irev(i-1))* dh_e(i);
den(i) = ((k * delta(i)) - (alpha * (M_an(i) - M_irev(i-1))));
% M_irev(i) = ((M_an(i) - M_irev(i-1)) / ((k * delta) - (alpha * (M_an(i) - M_irev(i-1))))) * dh_e(i);
M_irev(i) = num(i) / den(i);
% Update magnetization
M(i) = c*M_an(i) + (1-c)*M_irev(i);
end
%% Magnetic flux density
B = u_0 * (h + M);
%% Plot results
figure;
plot(h, B);
% plot(h, B, hh, BB, hh, Bs);
xlabel('Magnetic Field Strength');
ylabel('Magnetic Flux Density');
title('HB Graph');
grid on;
%% more plots (for debug purposes)
figure;
plot(M_an);
title('M-an');
figure;
plot(delta);
title('delta');
figure;
plot(num);
title('M-irev num');
figure;
plot(den);
title('M-irev den');
Md Tanbir Siddik
on 6 May 2024
Mathieu NOE
on 6 May 2024
ok, glad you have now a work around !
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







