sh_lin30 发表于 2017-2-22 10:39

求助如何画三维相空间图

利用数值可以得到二维杜芬系统的速度和位移,可以画三维曲线图,如何画三维网格图?

eastar 发表于 2017-2-22 11:01

function dx=Duffing(t,x,flag,f); global f; %Duffing方程
a=0.25;
b=-1;
c=1;
w=1;
dx=;
%fftplot幅值谱
function =fftplot(x,step)
= size(x);
if r == 1
      x = x.';   % make it a column
end;
= size(x);
m = 2^nextpow2(n);
y = fft(x,m);
y = y(1:n,:);
yy=abs(y)*step;
fid1=fopen('fft1.txt','w');
fid2=fopen('aft1.txt','w');
for kk=1:m/2+1;
   f(kk)=(kk-1)/m/step;
   fprintf(fid1,'%8.4f\n',f(kk));
   fprintf(fid2,'%8.4f\n',y(kk));
end
fclose(fid1);
fclose(fid2);
y=yy(1:m/2+1);
%plot(f,y);
%xlabel('Frequency (Hz)');
%ylabel('Fourier Amplitude');
%title('Fouier Transform of the Data')
%求解、绘图:时域波形、相平面、幅值谱、Poincare图、分岔图
clc
global f;
f=0.1
tspan=;
options=odeset('RelTol',1e-5,'AbsTol',1e-6);
=ode45('Duffing',tspan,,options);
x_data=x(:,1);
x_dot=x(:,2);
%时域波形
axes('FontSize',16,'FontName','Times New Roman','LineWidth',1.5);
hold on;
plot(tspan,x_data,'LineWidth',1.5);
xlim()
%xlim()
xlabel('\itt','Fontsize',20,'Fontname','Times new roman');%x轴标注
ylabel('\itx','Fontsize',20,'Fontname','Times new roman','Rotation',0);%y轴标注
grid on
box on
%相平面图
figure(2)
axes('FontSize',16,'FontName','Times New Roman','LineWidth',1.5);
hold on;
plot(x_data(1000:3000),x_dot(1000:3000),'LineWidth',1.5);
%plot(x_data(10:30000),x_dot(10:30000),'LineWidth',1.5);
xlabel('\itx','Fontsize',20,'Fontname','Times new roman');%x轴标注
ylabel('d\itx/d\itt','Fontsize',20,'Fontname','Times new roman');%y轴标注
grid on
box on
%幅值谱
=fftplot(x_data,0.01*2*pi);
figure(3)
axes('FontSize',16,'FontName','Times New Roman','LineWidth',1.5);
hold on;
xlim()
ylim()
plot(freq(1:5000),amp(1:5000),'LineWidth',1.5);
xlabel('/Hz','Fontsize',20,'Fontname','Times new roman');%x轴标注
ylabel('mu','Fontsize',20,'Fontname','Times new roman');%y轴标注
grid on
box on
%poincare图
x(:,2)=mod(x(:,2),2*pi)-pi;
phi0=pi*1;
for k=1:round(max(x(:,3))/2/pi);
    d=x(:,3)-(k-1)*2*pi-phi0;
    =sort(abs(d));
    x1l=x(K(1),1);
    x1r=x(K(2),1);
    x2l=x(K(1),2);
    x2r=x(K(2),2);
    x3l=x(K(1),3);
    x3r=x(K(2),3);
    if abs(P(1))+abs(P(2))<3e-16;
      X1(k)=x1l;
      X2(k)=x2l;
    else
      Q=polyfit(,,1);
      X1(k)=polyval(Q,(k-1)*2*pi-phi0);
         Q=polyfit(,,1);
      X2(k)=polyval(Q,(k-1)*2*pi-phi0);
    end
end
    figure(4)
   axes('FontSize',16,'FontName','Times New Roman','LineWidth',1.5);
   plot(X1,X2,'.');
xlabel('\itx','Fontsize',20,'Fontname','Times new roman');%x轴标注
ylabel('d\itx/d\itt','Fontsize',20,'Fontname','Times new roman');%y轴标注
%分岔图
global f
figure(5)
hold on;
box on;
xlim();
ylim([-2,2]);
N=80;
Tn=zeros(1,N);
options=odeset('RelTol',1e-9);
for f=0.05:.05:1;
x0=;
for n=1:60;
=ode45('Duffing',,x0,options);
x0=x(end,:);
end
for n=1:N;
=ode45('Duffing',,x0,options);
x0=x(end,:);
xd=x(:,1);
Tn(n)=max(xd);
end
f
plot(f,Tn,'b.','markersize',1);
pause(0.0001);
end
xlabel('\itf','Fontsize',16,'Fontname','Times new roman');%x轴标注
ylabel('\itx','Fontsize',16,'Fontname','Times new roman','Rotation',0);%y轴标注仅供参考

sh_lin30 发表于 2017-2-22 12:29

这个是相平面图 我希望是如图的相空间图

sh_lin30 发表于 2017-2-22 22:20

顶楼的相空间是如何画?自由度1的位移-速度-自由度2的位移

Pparis 发表于 2017-2-23 08:29

plot3meshgrid等命令不都能实现吗

sh_lin30 发表于 2017-2-23 16:58

plot3是画空间曲线,meshgrid要求z是矩阵

Apologize 发表于 2017-2-24 08:32

sh_lin30 发表于 2017-2-23 16:58
plot3是画空间曲线,meshgrid要求z是矩阵

matlab不就是针对矩阵进行的运算吗
页: [1]
查看完整版本: 求助如何画三维相空间图