How can I use custom equation in cftool?

조회 수: 2 (최근 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 CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by