x=[-3 -2.8 -2 -1.2 -1.2 -1.3 -0.1 0.1 1.3 1.5 1.8 2.5 3.2 3.5 3 2 1 0 -1 -2 -2.5 -3] ;
y=[0 1 1.2 1.5 2 3 3.7 3.8 3.5 2 1.5 1.5 1 0 -1 -2 -2.3 -2.7 -2.2 -1.9 -1 0];
[a,l]=cart2pol(x,y);
n=length(a);
a(n)=-a(n);
x1=-3.14:0.01:3.14;
y1=interp1(a,l,x1,'spline');
y2=interp1(a,l,x1,'cubic');
[x2,y3]=pol2cart(x1,y1);
[x3,y4]=pol2cart(x1,y2);
figure(1)
plot(x,y,'k+')
hold on
plot(x2,y3,'b-')
figure(2)
plot(x,y,'k+')
hold on
plot(x3,y4,'r-')
你给的是直角坐标,先将其转换为极坐标后用插值法得到中间值后在转换回去,就可以绘出图来了。由于不知道该曲线的极坐标形式的函数形式,我用了三次样条和三次多项式两种插值法得到的图效果都不怎么好。用多项式拟合的话效果更差,下面的程序是用多项式拟合的。你可以自己调整下拟合次数看看(为了计算方便,我将你的原始数据的后7个换到了前面,这样能保证极坐标的角度是单调递减的)
x=[-3 -2.8 -2 -1.2 -1.2 -1.3 -0.1 0.1 1.3 1.5 1.8 2.5 3.2 3.5 3 2 1 0 -1 -2 -2.5 -3] ;
y=[0 1 1.2 1.5 2 3 3.7 3.8 3.5 2 1.5 1.5 1 0 -1 -2 -2.3 -2.7 -2.2 -1.9 -1 0];
[a,l]=cart2pol(x,y);
n=length(a);
a(n)=-a(n);
x1=-3.14:0.01:3.14;
p1=polyfit(a,l,12);%12次多项式
p2=polyfit(a,l,14);%14次多项式
y1=polyval(p1,x1);
y2=polyval(p2,x1);
[x2,y3]=pol2cart(x1,y1);
[x3,y4]=pol2cart(x1,y2);
figure(1)
plot(x,y,'k+')
hold on
plot(x2,y3,'b-')
figure(2)
plot(x,y,'k+')
hold on
plot(x3,y4,'r-')
温馨提示:答案为网友推荐,仅供参考