How can I use custom equation in cftool?

1 回表示 (過去 30 日間)
Jenni
Jenni 2024 年 3 月 15 日
コメント済み: Jenni 2024 年 3 月 17 日
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 Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by