24小时热门版块排行榜    

查看: 387  |  回复: 2
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

2012200838

新虫 (正式写手)

[求助] 多项式拟合,报错说X,Y数据长度不一致,但是定义长度一样

报错信息:
CODE:
??? Error using ==> polyfit at 48
X and Y vectors must be the same size.

Error in ==> Test_fitting at 36
p_Ft=polyfit(theta_Mid,Kt,Degree);   

代码如下
CODE:
Fx=load('Fxx.txt');
Fy=load('Fyy.txt');

n     =length(Fx);                                     % Sample quantity of Fx,Fy
theta =zeros(n,1);                                     % Rotation angle
Ft    =zeros(n,1);                                     % Tangential force initialization

for k=1:n
    theta(k)=pi/n*k;                                   % Discretize the rotation angle
end
for k=1:n
    Ft(k)=-cos(theta(k))*Fx(k)+sin(theta(k))*Fy(k);    % Evaluate Ft
end

% Calculate Kt,Kr
ft          =0.1;                                      % Feed per tooth
ap          =3;                                        % Axial cutting depth
delta_theta =10;                                       % Set the angle-cut length at both ends (Unit: degree)
delta       =round(delta_theta/180*n);                 % Quantity of samples deserted   
theta_Mid   =zeros(n-2*delta,1);                       % Angle data for fitting initialization
Kt          =zeros(n-2*delta,1);                       % Coefficient of tangential force
Ft_fit      =zeros(n-2*delta,1);                       % Fitting of Tangential force initialization


for k=delta+1:n-delta
%   Kt(k)=Ft(k)/(ft*ap);      
    Kt(k)=Ft(k)/(ap*ft*sin(theta(k)));                 % Evaluate Kt within the given interval
end

for k=1:n-2*delta
   theta_Mid(k)=theta(k+delta);                        % Cut angle data near 0 and pi
end

Degree=5;                                              % Set the polynomial degree
p_Ft=polyfit(theta_Mid,Kt,Degree);                     % Evaluate the coefficients
Kt_fit=polyval(p_Ft,theta_Mid);

for k=delta+1:n-delta
%   Ft_fit(k)=ap*ft*Kt_fit(k);      %
    Ft_fit(k)=ap*ft*sin(theta(k))*Kt_fit(k);           % Fitting expression of Ft
end

% Output
%-------------------------------------------------------------------------%
figure(1)
set(gcf,'color','w')
plot(theta,Fx,'k')                                     % Fx
hold on
plot(theta,Fy,'b')                                     % Fy
grid on
legend('Fx,Fy')
%-------------------------------------------------------------------------%
figure(2)
set(gcf,'color','w')
plot(theta,Kt,'r')                                     % Kt
hold on
plot(theta,Kt_fit,'g')                                 % Kt_fit
hold on
grid on
legend('Kt','Kt-fit')
%-------------------------------------------------------------------------%
figure(3)
set(gcf,'color','w')
plot(theta,Ft,'r')                                     % Ft
hold on
plot(theta,Ft_fit,'g')                                 % Ft_fit
hold on
grid on
legend('Ft','Ft-fit')

回复此楼
生命就是一场旅行,不要错过了路边的风景!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

2012200838

新虫 (正式写手)

程序已无语法错误,但第二幅图,第三幅图不显示。
CODE:
Fx=load('Fxx.txt');
Fy=load('Fyy.txt');

n     =length(Fx);                                            % Sample quantity of Fx,Fy
theta =zeros(n,1);                                            % Rotation angle
Ft    =zeros(n,1);                                            % Tangential force initialization

for k=1:n
    theta(k)=pi/n*k;                                          % Discretize the rotation angle
end
for k=1:n
    Ft(k)=-cos(theta(k))*Fx(k)+sin(theta(k))*Fy(k);           % Evaluate Ft
end

% Calculate Kt,Kr
ft          =0.1;                                             % Feed per tooth
ap          =3;                                               % Axial cutting depth
delta_theta =10;                                              % Set the angle-cut length at both ends (Unit: degree)
delta       =round(delta_theta/180*n);                        % Quantity of samples deserted   
theta_Mid   =zeros(n-2*delta,1);                              % Angle data for fitting initialization
Kt          =zeros(n-2*delta,1);                              % Coefficient of tangential force
Ft_fit      =zeros(n-2*delta,1);                              % Fitting of Tangential force initialization


for k=delta+1:n-delta
%   Kt(k)=Ft(k)/(ft*ap);      
    Kt(k-delta)=Ft(k)/(ap*ft*sin(theta(k)));                  % Evaluate Kt within the given interval
end

for k=1:n-2*delta
   theta_Mid(k)=theta(k+delta);                               % Cut angle data near 0 and pi
end

Degree=5;                                                     % Set the polynomial degree
p_Ft=polyfit(theta_Mid,Kt,Degree);                            % Evaluate the coefficients
Kt_fit=polyval(p_Ft,theta_Mid);

for k=delta+1:n-delta
%   Ft_fit(k)=ap*ft*Kt_fit(k);      %
    Ft_fit(k-delta)=ap*ft*sin(theta(k))*Kt_fit(k-delta);      % Fitting expression of Ft
end

% Output
%-------------------------------------------------------------------------%
figure(1)
set(gcf,'color','w')
plot(theta,Fx,'k')                                     % Fx
hold on
plot(theta,Fy,'b')                                     % Fy
grid on
legend('Fx,Fy')
%-------------------------------------------------------------------------%
figure(2)
set(gcf,'color','w')
plot(theta,Kt,'r')                                     % Kt
hold on
plot(theta,Kt_fit,'g')                                 % Kt_fit
hold on
grid on
legend('Kt','Kt-fit')
%-------------------------------------------------------------------------%
figure(3)
set(gcf,'color','w')
plot(theta,Ft,'r')                                     % Ft
hold on
plot(theta,Ft_fit,'g')                                 % Ft_fit
hold on
grid on
legend('Ft','Ft-fit')

生命就是一场旅行,不要错过了路边的风景!
3楼2014-12-02 22:19:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 3 个回答

2012200838

新虫 (正式写手)

这是问题算法。
先谢谢了。。。

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : 问题算法.png
  • 2014-12-02 21:52:22, 31.54 K
生命就是一场旅行,不要错过了路边的风景!
2楼2014-12-02 21:53:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见