通过数据点拟合所需的曲线

时间:2014-01-13 05:28:22

标签: matlab plot sin

我有一组点,如下图所示 enter image description here

蓝点表示幅度减小的正弦曲线。这是我唯一的点。我将如何绘制精确追踪这些点的曲线(减小振幅sin曲线)。我尝试了正弦拟合,但它不起作用

我已编辑过添加以下全部代码

clc;clear all;
v = 1;t = 14.14;
for ink = 0:1:30
Wi = [0,0];Wf = [100,100];
line([0,100],[0,100],'color','g');

if(ink == 0)
uav_st = [10,0];
plot(uav_st(1,1),uav_st(1,2),'-x','MarkerSize',5);
chi = 0;
end

Ru = sqrt( ((Wi(1,1) - uav_st(1,1))^2)  + ((Wi(1,2) - uav_st(1,2))^2)  );
theta = atan2(Wf(1,2) - Wi(1,2) , Wf(1,1) - Wi(1,1));
theta_u = atan2(uav_st(1,2) - Wi(1,2),uav_st(1,1) - Wi(1,1));
beta = theta - theta_u;
R = sqrt(Ru^2 - (Ru*sin(beta))^2);
x_t = (R+ink)*cos(theta);
y_t = (R+ink)*sin(theta);
chi_d = (atan2(y_t - uav_st(1,2),x_t - uav_st(1,1)));
chi_r = chi_d*180/pi;
x_dot =(v*cos(chi_d));
y_dot =(v*sin(chi_d));
x_uav = x_dot*t+uav_st(1,1);
y_uav = y_dot*t+uav_st(1,2);
plot(x_uav,y_uav,'-x','MarkerSize',5);
%comet(x_uav,y_uav);
axis([0 100 0 100]);
axis('square');
uav_st(1,1) = x_uav;uav_st(1,2) = y_uav;
chi = chi_d;
pause(0.2);
hold on 
X_UAV(ink+1,1) = x_uav;
Y_UAV(ink+1,1) = y_uav;

end

ft=fittype('sin1');
cf=fit(X_UAV,Y_UAV,ft);
plot(cf);

上面曲线的最后三行给出正弦曲线拟合。你可以在你的机器上运行它来看看究竟发生了什么。这是正弦拟合给出的(红线非常接近绿线) enter image description here

感谢您的回复。

0 个答案:

没有答案