Matlab出现的问题
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/05/05 04:49:48
Matlab出现的问题
注意:分成1.2.3.级数【项数n分别为3、6、10】 求破.我数据都出来了.就是会出现数据乱排的现象.求程序.
注意:分成1.2.3.级数【项数n分别为3、6、10】 求破.我数据都出来了.就是会出现数据乱排的现象.求程序.
clear
clc
n=[3,6,10];%项数,可以任意加,任意改
m=length(n);
x=(0:0.2:2.0)';%自变量
y=ones(length(x),m);%近似值
for j=1:m
for i=1:n(j)
y(:,j)=1+y(:,j).*x/(n(j)+1-i);
end
end
%显示结果
disp([x,exp(x),y])
%画图
plot(x,y)
hold on
plot(x,exp(x),':k')
legend(strsplit([sprintf('n=%d,',n),'realval'],','),'Location','NorthWest')
运行结果:
0 1.0000 1.0000 1.0000 1.0000
0.2000 1.2214 1.2213 1.2214 1.2214
0.4000 1.4918 1.4907 1.4918 1.4918
0.6000 1.8221 1.8160 1.8221 1.8221
0.8000 2.2255 2.2053 2.2255 2.2255
1.0000 2.7183 2.6667 2.7181 2.7183
1.2000 3.3201 3.2080 3.3193 3.3201
1.4000 4.0552 3.8373 4.0527 4.0552
1.6000 4.9530 4.5627 4.9464 4.9530
1.8000 6.0496 5.3920 6.0341 6.0496
2.0000 7.3891 6.3333 7.3556 7.3890
绘制图像:
再问: 请问能不能生成上面我要的表格(就是问题的那个表格。) 然後用subplot,生成三个图像在一起,项数分别是3.6.10三幅图像。
再答: clear clc n=[3,6,10];%项数,可以任意加,任意改 m=length(n);%近似曲线的个数 x=(0:0.2:2.0)';%自变量 y=ones(length(x),m);%近似值 col=floor(sqrt(m));% subplot的列数 row=ceil(m/col);% subplot的行数 labels=strsplit(sprintf('n=%d,',n),',');%标签 for j=1:m for i=1:n(j) y(:,j)=1+y(:,j).*x/(n(j)+1-i); end %画图 subplot(row,col,j) hold on plot(x,y(:,j),'color',0.5+0.5*sin(([0,1,-1]+3*j/m)*2/3*pi))%近似曲线 plot(x,exp(x),'--k')%真实曲线 legend({labels{j},'realval'},'Location','NorthWest');%标签 end %显示结果 fprintf('x\t\t真实值\t') fprintf('n=%d\t\t',n) fprintf('\n') for k=1:length(x) fprintf('%.3f\t',[x(k),exp(x(k)),y(k,:)]) fprintf('\n') end
再问: 还是不行,我这边的MATLAB识别不了你的labels,strsplit。 Undefined variable "labels" or class "labels".
再答: clear clc n=[3,6,10];%项数,可以任意加,任意改 m=length(n);%近似曲线的个数 x=(0:0.2:2.0)';%自变量 y=ones(length(x),m);%近似值 col=floor(sqrt(m));% subplot的列数 row=ceil(m/col);% subplot的行数 for j=1:m for i=1:n(j) y(:,j)=1+y(:,j).*x/(n(j)+1-i); end %画图 subplot(row,col,j) hold on plot(x,y(:,j),'color',0.5+0.5*sin(([0,1,-1]+3*j/m)*2/3*pi))%近似曲线 plot(x,exp(x),'--k')%真实曲线 legend(sprintf('n=%d',n(j)),'realval','Location','NorthWest');%标签 end %显示结果 fprintf('x\t\t真实值\t') fprintf('n=%d\t\t',n) fprintf('\n') for k=1:length(x) fprintf('%.3f\t',[x(k),exp(x(k)),y(k,:)]) fprintf('\n') end
clc
n=[3,6,10];%项数,可以任意加,任意改
m=length(n);
x=(0:0.2:2.0)';%自变量
y=ones(length(x),m);%近似值
for j=1:m
for i=1:n(j)
y(:,j)=1+y(:,j).*x/(n(j)+1-i);
end
end
%显示结果
disp([x,exp(x),y])
%画图
plot(x,y)
hold on
plot(x,exp(x),':k')
legend(strsplit([sprintf('n=%d,',n),'realval'],','),'Location','NorthWest')
运行结果:
0 1.0000 1.0000 1.0000 1.0000
0.2000 1.2214 1.2213 1.2214 1.2214
0.4000 1.4918 1.4907 1.4918 1.4918
0.6000 1.8221 1.8160 1.8221 1.8221
0.8000 2.2255 2.2053 2.2255 2.2255
1.0000 2.7183 2.6667 2.7181 2.7183
1.2000 3.3201 3.2080 3.3193 3.3201
1.4000 4.0552 3.8373 4.0527 4.0552
1.6000 4.9530 4.5627 4.9464 4.9530
1.8000 6.0496 5.3920 6.0341 6.0496
2.0000 7.3891 6.3333 7.3556 7.3890
绘制图像:
再问: 请问能不能生成上面我要的表格(就是问题的那个表格。) 然後用subplot,生成三个图像在一起,项数分别是3.6.10三幅图像。
再答: clear clc n=[3,6,10];%项数,可以任意加,任意改 m=length(n);%近似曲线的个数 x=(0:0.2:2.0)';%自变量 y=ones(length(x),m);%近似值 col=floor(sqrt(m));% subplot的列数 row=ceil(m/col);% subplot的行数 labels=strsplit(sprintf('n=%d,',n),',');%标签 for j=1:m for i=1:n(j) y(:,j)=1+y(:,j).*x/(n(j)+1-i); end %画图 subplot(row,col,j) hold on plot(x,y(:,j),'color',0.5+0.5*sin(([0,1,-1]+3*j/m)*2/3*pi))%近似曲线 plot(x,exp(x),'--k')%真实曲线 legend({labels{j},'realval'},'Location','NorthWest');%标签 end %显示结果 fprintf('x\t\t真实值\t') fprintf('n=%d\t\t',n) fprintf('\n') for k=1:length(x) fprintf('%.3f\t',[x(k),exp(x(k)),y(k,:)]) fprintf('\n') end
再问: 还是不行,我这边的MATLAB识别不了你的labels,strsplit。 Undefined variable "labels" or class "labels".
再答: clear clc n=[3,6,10];%项数,可以任意加,任意改 m=length(n);%近似曲线的个数 x=(0:0.2:2.0)';%自变量 y=ones(length(x),m);%近似值 col=floor(sqrt(m));% subplot的列数 row=ceil(m/col);% subplot的行数 for j=1:m for i=1:n(j) y(:,j)=1+y(:,j).*x/(n(j)+1-i); end %画图 subplot(row,col,j) hold on plot(x,y(:,j),'color',0.5+0.5*sin(([0,1,-1]+3*j/m)*2/3*pi))%近似曲线 plot(x,exp(x),'--k')%真实曲线 legend(sprintf('n=%d',n(j)),'realval','Location','NorthWest');%标签 end %显示结果 fprintf('x\t\t真实值\t') fprintf('n=%d\t\t',n) fprintf('\n') for k=1:length(x) fprintf('%.3f\t',[x(k),exp(x(k)),y(k,:)]) fprintf('\n') end
Matlab出现的问题
Matlab 出现的子函数输出问题.
下面的matlab程序画图出现什么问题?
MATLAB/Simulink仿真时出现下面的问题,
关于matlab/simulink仿真过程出现的问题!
用matlab中的maple中解不等式出现的问题
MATLAB使用过程中出现问题,
matlab中contourf函数出现问题
Matlab for循环出现小问题
初学matlab,出现问题,求大神指导!
我编辑的matlab函数老是出现这种问题:Error using spirallength (line 9) Not e
关于matlab/simulink仿真过程出现的inf和NaN问题!