Effacer les filtres
Effacer les filtres

How can I use custom equation in cftool?

2 vues (au cours des 30 derniers jours)
Jenni
Jenni le 15 Mar 2024
Commenté : Jenni le 17 Mar 2024
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! :)

Réponse acceptée

VBBV
VBBV le 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 commentaires
Sam Chak
Sam Chak le 15 Mar 2024
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 le 17 Mar 2024
Thank you @VBBV and @Sam Chak for your comments! With your help I solved the problem!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by