使用最小二乘法求桥梁​桩身受力,结果系数飚​到11次方了,求教一​下是什么问题

1 回表示 (過去 30 日間)
锐
2022 年 11 月 3 日
回答済み: Abhishek 2023 年 9 月 12 日
%此函数用于计算火车经过时桥梁沿桩身不同位置的受力曲线
%使用方法为最小二乘法
%Aa+Bb=D
%Ba+Cb=E
%所有输出结果均保留三位有效数字
%图像显示至第100次,即66.7s处
function regression()
N=[1,10,100,1000,2500,5000,10000]; %次数
t=N*0.667; %时间
h=[2,8,26,38,56,66,96]; %深度
w=2*pi()/0.667;
x=[5.59 5.49 5.42 5.39 5.32 5.25 5.28;%原始数据
4.80 4.75 4.72 4.59 4.50 4.42 4.36;
3.67 3.69 3.71 3.67 3.60 3.48 3.41;
3.27 3.30 3.33 3.34 3.41 3.46 3.50;
2.69 2.74 2.89 2.96 2.84 2.62 2.59;
2.30 2.33 2.35 2.50 2.57 2.41 2.29;
2.02 2.04 2.09 2.18 2.22 2.30 2.36];
a=zeros(7,1);b=zeros(7,1); %拟合函数系数初始化
A=7;B=0;C=0; %最小二乘法系数初始化
for i=1:7 %系数计算
B=B+sin(w*t(i));
C=C+(sin(w*t(i)))^2;
end
for i=1:7
E=0;D=0;
for j=1:7
D=D+x(i,j);
E=E+x(i,j)*sin(w*t(j));
end
a(i)=(D*C-B*E)/(A*C-B*B);
b(i)=(A*E-D*B)/(A*C-B*B);
end
for i=1:7 %输出函数结果和图像
if(b(i)>0)
disp(['在',num2str(h(i)),'cm深度的拟合函数为:f',num2str(i),'=',num2str(a(i),3),'+',num2str(b(i),3),'*','sin(',num2str(w,3),'t)']);
else
disp(['在',num2str(h(i)),'cm深度的拟合函数为:f',num2str(i),'=',num2str(a(i),3),num2str(b(i),3),'*','sin(',num2str(w,3),'t)']);
end
t0 = linspace(0,40000,20000);
f = a(i)+b(i)*sin(w*t0);
figure;
plot(t0,f,t(1:7),x(i,1:7),'.');
xlabel('t');
ylabel('f(t)=a+b*sin(w*t)');
legend('regression','data');
end
end
2cm深度的拟合函数为:f1=5.45+2.9e+10*sin(9.42t)
8cm深度的拟合函数为:f2=4.7+4.92e+10*sin(9.42t)
26cm深度的拟合函数为:f3=3.68+3.65e+10*sin(9.42t)
38cm深度的拟合函数为:f4=3.32-2.57e+10*sin(9.42t)
56cm深度的拟合函数为:f5=2.83+2.99e+10*sin(9.42t)
66cm深度的拟合函数为:f6=2.41+6.15e+09*sin(9.42t)
96cm深度的拟合函数为:f7=2.09-3.81e+10*sin(9.42t)

回答 (1 件)

Abhishek
Abhishek 2023 年 9 月 12 日
Hi,
I understand you are getting incorrect results while calculating coefficients for the force on the bridge pile body using the least squares method.
Upon reviewing the provided code, I have identified that the issue lies in the initial values assigned to the least square coefficients. The least square coefficients are too small and even after calculating they remain relatively small.
To resolve this issue, I suggest you assign a greater initial value to the least square coefficients. You may directly assign greater values to A, B, and C variable.
Furthermore, please verify that you are following the correct method to update these coefficients.
I hope this helps!

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!