MATLAB—csape斜率拟合

  • Post author:
  • Post category:其他


在这里插入图片描述

function mycsap1()
%指定斜率csape显式拟合

%把测量得到的数据放入程序
 px= [0	0.6283	1.2566	1.8850	2.5133	3.1416	3.7699	4.3982	5.0265	5.6549	6.2832];
 py= [1.0000	0.8090	0.3090	-0.3090	-0.8090	-1.0000	-0.8090	-0.3090	0.3090	0.8090	1.0000];
 valconds=[0,0];%这是首末端点的斜率
 %把测量得到的数据放入程序
pp = csape(px,py,'complete',valconds);
x=0:6.2832/60:6.2832;
%规定密化点的横坐标
y=fnval(pp,x);%计算密化点的纵坐标
plot(x,y,'b.','MarkerSize',8);%绘制密化点便于观察
hold on
plot(x,y,'g');%把密化点连接成绿颜色的曲线
plot(px,py,'k.','MarkerSize',15);
%绘制型值点
hold off
axis equal
%%%%%%%%%%%%%%%%%%%%%%

在这里插入图片描述

function mycsap2()
%指定斜率csape显式拟合

%把测量得到的数据放入程序
 px= [-1.000	-0.8068	-0.3078 0.3078	0.8068	1.000];
 py= [0.0063 0.5908	0.9514	0.9514	0.5908	0.0063];
 valconds=[159.1529, -159.1529];%这是首末端点的斜率
 %把测量得到的数据放入程序
pp = csape(px,py,'complete',valconds);

x=1.0:-2.0/50:-1.0;%注意起始点的位置和点列的走向
%规定密化点的横坐标
y=fnval(pp,x);%计算密化点的纵坐标
plot(x,y,'b.','MarkerSize',8);%绘制密化点便于观察
hold on
plot(x,y,'g');%把密化点连接成绿颜色的曲线
plot(px,py,'k.','MarkerSize',15);
%绘制型值点
hold off
axis equal
%%%%%%%%%%%%%%%%%%%%%%

在这里插入图片描述

function mycsap3()
%指定斜率csape拟合
%参数方程拟合
 px= [-1.000	-0.8068	-0.3078 0.3078	0.8068	1.000];
 py= [0.0063 0.5908	0.9514	0.9514	0.5908	0.0063];
 valconds=[159.1529, -159.1529];
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%输入原始数据
 Ps=[px',py'];
 ss = AccuArcL(Ps);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%累加弦长获取参数
 c=0.5;%%%%%%比例参数
 Ls=ss(2);%获取两个型值点连线的长度
 rs=[1,159.1529];%在起始切线上根据数据点的走向取切向量
 rs = rs/sqrt(rs*rs');%切向量单位化
 rs = c*Ls*rs;%取与弦长成合适比例的切向量
 %%%从而得到起始位置的切向量
 n=length(ss);
 Le=ss(n)-ss(n-1);
 re=[1,-159.1529];
 re = re/sqrt(re*re');
 re = c*Le*re;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%根据斜率值构造终了点位置切向量
valconds=[rs(1) re(1)];
ppx = csape(ss,px,'complete',valconds);
fnbrk(ppx)%观察分段多项式函数
%观察分段多项式函数,新知识点,重要
valconds=[rs(2) re(2)];
ppy = csape(ss,py,'complete',valconds);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%构造参数三次样条
sm=ss(1):ss(n)/50:ss(n);
x=fnval(ppx,sm);
y=fnval(ppy,sm);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%进行数据密化采样,以便绘制曲线
plot(x,y,'b.','MarkerSize',8);
hold on
plot(x,y,'g');
plot(px,py,'k.','MarkerSize',15);
hold off
axis equal
 %%%%%%%%%%%%%%%%%%%%%%
The input describes a pp form

breaks(1:l+1)
         0    0.6156    1.2313    1.8469    2.4625    3.0781

coefficients(d*l,k)
   -0.0646    0.5464    0.0019   -1.0000
   -0.1417    0.4271    0.6013   -0.8068
   -0.1791    0.1654    0.9661   -0.3078
   -0.1417   -0.1654    0.9661    0.3078
   -0.0646   -0.4271    0.6013    0.8068

pieces number l
     5

order k
     4

dimension d of target
     1```
```clike
function ss = AccuArcL(Ps)
%累加弦长Ps是n行d列的数组
%输出每个点对应的参数值
[n,d]=size(Ps);
%测量数组的维度
ss(1)=0;
for i=2:n
    tv=Ps(i,:)-Ps(i-1,:);% Ps(i,:)表示取矩阵的第i行
    %这里就是第i个点的坐标
    %tv是相邻两个点形成的向量
    ss(i)=ss(i-1)+sqrt(tv*tv');
    %sqrt(tv*tv')表示向量tv的长度
end
function mycsap4()
%指定斜率csape拟合
%参数方程拟合
 px= [-1.000	-0.8068	-0.3078 0.3078	0.8068	1.000];
 py= [0.0063 0.5908	0.9514	0.9514	0.5908	0.0063];
 valconds=[159.1529, -159.1529];
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%输入原始数据
 Ps=[px',py'];
 ss = AccuArcL(Ps);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%累加弦长获取参数
 c=0.5;%%%%%%比例参数
 Ls=ss(2);%获取两个型值点连线的长度
 rs=[1,159.1529];%在起始切线上根据数据点的走向取切向量
 rs = rs/sqrt(rs*rs');%切向量单位化
 rs = c*Ls*rs;%取与弦长成合适比例的切向量
 %%%从而得到起始位置的切向量
 n=length(ss);
 Le=ss(n)-ss(n-1);
 re=[1,-159.1529];
 re = re/sqrt(re*re');
 re = c*Le*re;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%根据斜率值构造终了点位置切向量
pxy = [px;py];%构造一个矩阵,每列表示一个点
valconds=[rs(1) re(1);rs(2) re(2)];
pp = csape(ss,pxy,'complete',valconds);
fnbrk(pp)%观察分段多项式函数
%观察分段多项式函数,新知识点,重要
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%构造参数三次样条
sm=ss(1):ss(n)/50:ss(n);
xy=fnval(pp,sm);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%进行数据密化采样,以便绘制曲线
plot(xy(1,:),xy(2,:),'b.','MarkerSize',8);
hold on
plot(xy(1,:),xy(2,:),'g');
plot(px,py,'k.','MarkerSize',15);
hold off
axis equal
 %%%%%%%%%%%%%%%%%%%%%%```
![在这里插入图片描述](https://img-blog.csdnimg.cn/c0fea987cabb4d51a7848c4268ab36a5.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5a6HMjAyMg==,size_17,color_FFFFFF,t_70,g_se,x_16)

```handlebars
The input describes a pp form

breaks(1:l+1)
         0    0.6156    1.2313    1.8469    2.4625    3.0781

coefficients(d*l,k)
   -0.0646    0.5464    0.0019   -1.0000
   -1.5272    1.9825    0.3078    0.0063
   -0.1417    0.4271    0.6013   -0.8068
    0.2354   -0.8379    1.0124    0.5908
   -0.1791    0.1654    0.9661   -0.3078
   -0.0000   -0.4033    0.2482    0.9514
   -0.1417   -0.1654    0.9661    0.3078
   -0.2354   -0.4033   -0.2482    0.9514
   -0.0646   -0.4271    0.6013    0.8068
    1.5272   -0.8379   -1.0124    0.5908

pieces number l
     5

order k
     4

dimension d of target
     2



版权声明:本文为m0_38127487原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。