作业帮 > 综合 > 作业

x=[58 56 54 48 40 33 20 0 -20 -40 -48 -50 -53 -58 56 53 50 4

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/30 05:11:40
x=[58 56 54 48 40 33 20 0 -20 -40 -48 -50 -53 -58 56 53 50 48 20 0 36 -48 -54 -55 -55];
>> y=[1400 1200 1000 500 150 0 -280 -450 -600 -800 -1000 -1100 -1200 -1400 1300 1200 1100 1000 650 500 0 -500 -900 -1100 -1200];
高手们帮帮忙
matlab中如何画出这些数据的图形,要连续的曲线.不需要散点图.听说需要三次样条插值
x(21)有问题,应该是-36,不是36.
clear;clc;close all;
warning off all;
x=[58 56 54 48 40 33 20 0 -20 -40 -48 -50 -53 -58 56 53 50 48 20 0 -36 -48 -54 -55 -55];
y=[1400 1200 1000 500 150 0 -280 -450 -600 -800 -1000 -1100 -1200 -1400 1300 1200 1100 1000 650 500 0 -500 -900 -1100 -1200];
%数据构成循环,并作出反函数:
X=[y(1:14),y(end:-1:15),y(1)];
Y=[x(1:14),x(end:-1:15),x(1)];
%绘制原图形的概貌
plot(X,Y);
hold on;
%拟合成两条三次曲线:
for n=1:3:12,
X1=X(n:n+3);
Y1=Y(n:n+3);
A1=polyfit(X1,Y1,3);
%提取系数:
a1=A1(1);
b1=A1(2);
c1=A1(3);
d1=A1(4);
%画拟合曲线:
X1=min(X1):max(X1);
plot(X1,a1.*X1.^3+b1.*X1.^2+c1.*X1+d1,'r');
end;
for n=15:3:length(X)-3,
X2=X(n:n+3);
Y2=Y(n:n+3);
A2=polyfit(X2,Y2,3);
a2=A2(1);
b2=A2(2);
c2=A2(3);
d2=A2(4);
X2=min(X2):max(X2);
plot(X2,a2*X2.^3+b2*X2.^2+c2.*X2+d2,'r');
end;
plot(X(13:15),Y(13:15),'r');
plot(X(24:end),Y(24:end),'r');
hold off;