How can I use custom equation in cftool?
2 views (last 30 days)
Show older comments
Hey!
I am trying to plot the magnitude of the magnetic field along the axis of symmetry of the magnet as a function of the distance from the surface of the magnet. But I have a problem to find a way to use custom equation in cftool space. My equation would be:
,
where
μ_0 = 1.25663706212 × 10−6 H/m (Permeability in vacuum)
M = slope
z = data point
R = 0.4 * 10^-2 m (radius)
L = 0.5*10^-2 m. (height)
So this equation I would like to fit to my data points. How could I replace the circled equation with my own one?
Here is my data:
data = [0.1218 0.0643 0.0389 0.0268 0.0186 0.0139 0.0107 0.0085 0.007 0.0057 0.0045 0.0035];
number of data points = 1:1:12;
Thank you for your help! :)
0 Comments
Accepted Answer
VBBV
on 15 Mar 2024
In the custom equation, function box , replace the x with z and define the equation as in your case in the box below
3 Comments
Sam Chak
on 15 Mar 2024
Hi @Jenni
Could you please verify if there is only a single free parameter (slope) M in your proposed model? Additionally, it would be helpful if you could check whether I entered the Magnetic Field equation correctly.
%% data
zdat = (1:12)';
Bdat = [0.1218 0.0643 0.0389 0.0268 0.0186 0.0139 0.0107 0.0085 0.007 0.0057 0.0045 0.0035]';
%% fixed parameters
mu0 = 1.25663706212e-6; % H/m (Permeability in vacuum)
R = 0.4e-2; % m (radius)
L = 0.5e-2; % m (height)
%% proposed model by the OP
z = linspace(1, 12, 1301);
B = @(M, z) (mu0*M/2)*(z./sqrt(z.^2 + R^2) - (z - L)./sqrt((z - L).^2 + R^2));
%% plot and compare
plot(zdat, Bdat, 'o'), hold on
plot(z, B(2.4e12, z)), grid on
legend('data points', 'fitted curve', 'fontsize', 20)
title('Magnetic Field'), xlabel z, ylabel B(z)
More Answers (0)
See Also
Categories
Find more on Interpolation 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!