周围很多uu说磁阻尼现象的实验数据很难处理,或是origin上的自定义拟合函数不会用。如果电脑上装了matlab的uu也可以尝试一下以下代码(只需要把矩阵中原数据改为你实验测出来的数据就可以啦)
l=(29+0.02*1)/1000;%磁铁的长
w=(4+0.02*33)/1000;%磁铁的宽
dx=(50+0.02*1)/1000;%△x
%1.磁阻尼与磁场纵向长度关系(全部为国际单位制):
time_direction=[251.1 256.7 263.7 269.2 276.6 285.6 295.2 307.2;
129.1 129.7 131.2 132.2 132.7 134.1 135.2 136.7;
96.50 97.17 97.70 98.17 98.24 99.12 99.51 100.7;
127.1 127.6 128.7 129.6 130.2 131.6 132.7 134.2;
104.6 105.2 106.1 106.2 106.6 107.7 108.1 109.1;
76.10 76.21 76.24 76.62 76.72 77.24 77.64 78.12];
time_direction=time_direction./1000;%时间1
t_direction=[0 612 1392 2018 2806 3538 4239 5041;
0 313 706 1016 1400 1750 2077 2442;
0 234 526 757 1042 1301 1542 1811;
0 308 693 998 1375 1718 2039 2397;
0 254 571 821 1130 1411 1673 1965;
0 184 413 594 817 1019 1207 1415];
t_direction=t_direction./1000;%时刻1
v_direction=time_direction.^(-1).*dx;%用时间算速度
ln_v_direction=log(v_direction);
for i=1:6
x=t_direction(i,:)';
[m,n]=size(x);
X=[ones(m,1) x];
Y=ln_v_direction(i,:)';
[b]=regress(Y,X);
k_direction(i)=-b(2);%每组的斜率k
wi(i)=i*w;
end
x=wi';
[m,n]=size(x);
X=[ones(m,1) x];
Y=k_direction';
[xs]=regress(Y,X);%k与wi的关系
a=xs(2);b=xs(1);%y=ax+b,此处x为w,y为k
z=b+a.*x;
plot(x,Y,'ko',x,z,'r');
grid on;
xlabel("磁铁的宽w");
ylabel("K");
title("(ki~wi)的关系");
txt1=['磁阻尼与磁场纵向长度的关系拟合函数:k=aw+b'];
txt2=['拟合系数a为:' num2str(a)];
txt3=['拟合系数b为:' num2str(b)];
text(0.007,0.0247,txt1);
text(0.007,0.02435,txt2);
text(0.007,0.0240,txt3);
%2.磁阻尼与磁场横向长度关系(全部为国际单位制):
time_transverse=[165.1 166.7 168.6 170.1 172.1 174.6 177.2 180.7;
146.6 147.6 149.2 150.2 151.5 153.7 155.6 158.2;
136.6 138.2 140.1 141.6 143.6 145.6 147.6 150.2;
94.21 95.12 96.24 97.12 98.21 99.12 100.0 101.2;
98.13 98.71 100.1 101.2 101.7 103.2 104.1 105.5;
125.6 127.7 130.2 131.6 133.7 136.6 138.7 141.1];
time_transverse=time_transverse./1000;
t_transverse=[0 400 903 1303 1799 2253 2679 3158;
0 355 801 1154 1592 1991 2366 2787;
0 332 750 1082 1495 1873 2228 2627;
0 229 517 745 1028 1286 1528 1798;
0 238 536 774 1068 1337 1588 1870;
0 306 693 1002 1387 1740 2073 2447];
t_transverse=t_transverse./1000;
v_transverse=time_transverse.^(-1).*dx;%用时间算速度
ln_v_transverse=log(v_transverse);
for i=1:6
x=t_transverse(i,:)';
[m,n]=size(x);
X=[ones(m,1) x];
Y=ln_v_transverse(i,:)';
[b]=regress(Y,X);
k_transverse(i)=-b(2);%每组的斜率k
li(i)=i*l;
end
fun_2 = @(x,l)(x(1).*l+x(2))./(1+x(3).*l);%拟合的分式函数
x0 = [1,1,1];%三个系数的初始值
lb=[];%约束条件为空
ub=[];
[x_1,resnorm,residual,exitflag,output,lambda,jacobian]= lsqcurvefit(fun_2,x0,li,k_transverse,lb,ub);%x_1为a,b,c三个系数所构成的矩阵
temp=linspace(min(li),max(li),10000);
z=(x_1(1).*temp+x_1(2))./(1+x_1(3).*temp);
plot(li,k_transverse,'ko',temp,z,'r');
grid on;
xlabel("磁铁的长L");
ylabel("K");
title("(ki~li)的关系");
txt1=['磁阻尼与磁场横向长度的关系拟合函数:k=(ax+b)/(1+cx)'];
txt2=['拟合系数a为:' num2str(x_1(1))];
txt3=['拟合系数b为:' num2str(x_1(2))];
txt4=['拟合系数c为:' num2str(x_1(3))];
text(0.03,0.049,txt1);
text(0.03,0.0478,txt2);
text(0.03,0.0466,txt3);
text(0.03,0.0454,txt4);
%1.磁阻尼与磁场强度关系(全部为国际单位制):
time_strength=[141.1 142.2 144.1 145.1 146.1 148.1 149.7 151.7;
145.6 147.2 149.6 151.6 153.6 156.1 158.7 161.7;
118.6 119.7 121.1 122.2 123.7 126.1 127.6 130.1;
147.6 149.6 153.2 155.6 159.1 162.7 166.5 171.6;
194.6 199.7 206.6 212.6 220.6 229.6 239.7 253.2;
86.13 87.21 89.21 90.21 91.62 93.21 94.70 96.12];
time_strength=time_strength./1000;
t_strength=[0 343 773 1113 1536 1921 2282 2686;
0 354 800 1155 1596 2001 2383 2812;
0 288 649 937 1294 1620 1927 2272;
0 359 812 1175 1630 2051 2449 2900;
0 474 1081 1573 2197 2783 3348 4002;
0 209 473 685 948 1190 1417 1672];
t_strength=t_strength./1000;
v_strength=time_strength.^(-1).*dx;%用时间算速度
ln_v_strength=log(v_strength);
for i=1:6
x=t_strength(i,:)';
[m,n]=size(x);
X=[ones(m,1) x];
Y=ln_v_strength(i,:)';
[b]=regress(Y,X);
k_strength(i)=-b(2);%每组的斜率k
Bi(i)=i.^2;
end
k_strength
x=Bi';
[m,n]=size(x);
X=[ones(m,1) x];
Y=k_strength';
[xs]=regress(Y,X);%k与wi的关系
a=xs(2);b=xs(1);%y=ax+b,此处x为i,y为B²
z=b+a.*x;
plot(x,Y,'ko',x,z,'r');
grid on;
xlabel("B²(块)²");
ylabel("K");
title("(ki~B²i)的关系");
txt1=['磁阻尼与磁场强度的关系拟合函数:k=ai+b'];
txt2=['拟合系数a为:' num2str(a)];
txt3=['拟合系数b为:' num2str(b)];
text(4,0.073,txt1);
text(4,0.070,txt2);
text(4,0.067,txt3);
跑出来拟合曲线如下图所示:
这样只需要改写输入的数据就可以实现拟合曲线的绘制啦,不需要过多的繁琐操作
备注:txt文字在图像中的位置记得自己改一下,或者删掉也行,不然不同图像文字位置偏差可能会很大