24小时热门版块排行榜    

查看: 469  |  回复: 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

新虫 (正式写手)

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

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱: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的回帖

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的回帖
相关版块跳转 我要订阅楼主 2012200838 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 2019年青年基金涵评意见,大家看看几个A,几个B? +8 Tide man 2026-08-11 8/400 2026-08-12 17:30 by Vivilian
[基金申请] 好奇怪的filecode +5 布布和一二 2026-08-08 6/300 2026-08-12 16:11 by 云上清扬
[基金申请] FileCode能看出啥? +8 要乐观耀哥 2026-08-10 21/1050 2026-08-12 16:08 by 云上清扬
[基金申请] filecode +13 documentary 2026-08-10 15/750 2026-08-12 15:56 by 云上清扬
[论文投稿] 职称评审,求友友推荐见刊最快的期刊 +4 工厂打螺丝 2026-08-08 4/200 2026-08-12 09:18 by hansi2025
[基金申请] 综述论文作为代表作会不会影响评审专家的印象分? +11 yufeiwaner 2026-08-09 13/650 2026-08-12 08:17 by yufeiwaner
[硕博家园] 读博的好处 +3 lnee 2026-08-11 3/150 2026-08-11 18:10 by 希望我好好的
[基金申请] 听说今天filecode变了 +26 布布和一二 2026-08-06 49/2450 2026-08-11 13:18 by WH3796
[基金申请] 关于代码变化问题,想知道的进来 +17 且听虎啸 2026-08-07 24/1200 2026-08-10 18:35 by zhangduo2008
[基金申请] 静等基金结果 +5 gjjjzhong 2026-08-10 16/800 2026-08-10 17:19 by Tide man
[基金申请] 国自然结果 +4 Vierhys 2026-08-10 8/400 2026-08-10 15:06 by Vierhys
[基金申请] 2026国自然放榜时间 +9 布布和一二 2026-08-08 9/450 2026-08-10 11:22 by xxxx2020
[基金申请] 这样的filecode谁见过 +11 布布和一二 2026-08-08 22/1100 2026-08-10 11:10 by wmfsnow
[基金申请] filecode与中标关系的预测 +5 布布和一二 2026-08-07 5/250 2026-08-09 16:15 by 袁向阳007
[基金申请] fileCode有新解读? +10 Tide man 2026-08-08 18/900 2026-08-09 12:55 by 仁砚薪传
[基金申请] 关于filecode,很负责任的告诉大家 +6 爱看书的可乐 2026-08-08 7/350 2026-08-08 22:13 by a_niu
[基金申请] 关于豆爷回答的JTJC与%2F数量 +5 yang182083 2026-08-06 7/350 2026-08-08 18:29 by zhanghaozhu
[基金申请] 关于filecode +4 布布和一二 2026-08-07 7/350 2026-08-07 22:55 by zhanghaozhu
[基金申请] 化学口download_prp&fileCode的固定段好像这几天一直没变,有变的大神么? +3 Tide man 2026-08-07 4/200 2026-08-07 22:39 by Tide man
[基金申请] 大家散了吧,后缀研究没有意义,别浪费时间了,过好目前的每一天,不要焦虑 +5 Tide man 2026-08-06 7/350 2026-08-07 13:11 by 医学老男孩
信息提示
请填处理意见