How can I use custom equation in cftool?

2 次查看(过去 30 天)
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! :)

采纳的回答

VBBV
VBBV 2024-3-15
In the custom equation, function box , replace the x with z and define the equation as in your case in the box below
  3 个评论
Sam Chak
Sam Chak 2024-3-15
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)
Jenni
Jenni 2024-3-17
Thank you @VBBV and @Sam Chak for your comments! With your help I solved the problem!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by