figPlot.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. close all;
  2. %% 初始化参数
  3. [Mission_Param, Environment_Param, Normalized_Param] = paraSet();
  4. % global Mission_Param Environment_Param Normalized_Param
  5. Re = Environment_Param.Re;
  6. g0 = Environment_Param.g0;
  7. m0 = Environment_Param.m0;
  8. P0 = Mission_Param.P0;
  9. ex0 = Mission_Param.ex0;
  10. ey0 = Mission_Param.ey0;
  11. hx0 = Mission_Param.hx0;
  12. hy0 = Mission_Param.hy0;
  13. L0 = Mission_Param.L0;
  14. Pf = Mission_Param.Pf;
  15. exf = Mission_Param.exf;
  16. eyf = Mission_Param.eyf;
  17. hxf = Mission_Param.hxf;
  18. hyf = Mission_Param.hyf;
  19. tscale = Normalized_Param.tscale;
  20. Lscale = Normalized_Param.Lscale;
  21. % Read = load('./data/data-200.txt');
  22. Read = readmatrix("data\data-200.txt");
  23. x0 = Read(end,4:10);
  24. % x0 = X;
  25. %% 积分
  26. tf = x0(7);
  27. state0 = zeros(26,1);
  28. state0(1:13) = [P0 ex0 ey0 hx0 hy0 L0 x0(1) x0(2) x0(3) x0(4) x0(5) x0(6) m0 ]';
  29. timespan = [0,tf*1000];
  30. options = odeset('RelTol',3e-14,'AbsTol',1e-14);
  31. Mu = 0.0;
  32. Lambda = 0.0;
  33. [tt1,xx1] = ode113(@dynamicModel_InverseGauss,timespan,state0,options,Mu, Lambda,tf, Environment_Param);
  34. %各个值
  35. P = xx1(:,1)*Lscale;
  36. ex = xx1(:,2);
  37. ey = xx1(:,3);
  38. hx = xx1(:,4);
  39. hy = xx1(:,5);
  40. L = xx1(:,6);
  41. %% modified equinoctial orbit elements --> orbital elements
  42. %参数转换
  43. e = sqrt(ex.^2+ey.^2);
  44. a = P./(1-e.^2);
  45. i = 2*atan(sqrt(hx.^2+hy.^2));
  46. Omega = atan2(hy,hx);
  47. omega = atan2(ey,ex)-Omega;
  48. f = L-Omega-omega;
  49. e_f = sqrt(exf^2+eyf^2);
  50. a_f = Pf*Lscale/(1-e_f^2);
  51. i_f = 2*atan(sqrt(hxf^2+hyf^2));
  52. Omega_f = atan2(hyf,hxf);
  53. omega_f = atan2(eyf,exf)-Omega_f;
  54. f_f = -Omega_f-omega_f;
  55. X_save = OE_to_GEI(a,e,i,Omega,omega,f);
  56. X_f = OE_to_GEI(a_f,e_f,i_f,Omega_f,omega_f,f_f);
  57. %% 绘制轨道根数变化
  58. figure(1)
  59. plot(tt1*tscale/3600,P/1000,'-','linewidth',2);grid on;xlabel('time(h)');ylabel('P(km)');
  60. hold on
  61. scatter(tt1(end)*tscale/3600,P(end)/1000,200,"pentagram",'filled');
  62. legend('',"End Point",'Location','southeast')
  63. figure(2)
  64. plot(tt1*tscale/3600,ex,'-','linewidth',2);grid on;xlabel('time(h)');ylabel('e_x');
  65. hold on
  66. scatter(tt1(end)*tscale/3600,ex(end),200,"pentagram",'filled');
  67. legend('',"End Point",'Location','southeast')
  68. figure(3)
  69. plot(tt1*tscale/3600,ey,'-','linewidth',2);grid on;xlabel('time(h)');ylabel('e_y');
  70. hold on
  71. scatter(tt1(end)*tscale/3600,ey(end),200,"pentagram",'filled');
  72. legend('',"End Point",'Location','southeast')
  73. figure(4)
  74. plot(tt1*tscale/3600,hx,'-','linewidth',2);grid on;xlabel('time(h)');ylabel('h_x');
  75. hold on
  76. scatter(tt1(end)*tscale/3600,hx(end),200,"pentagram",'filled');
  77. legend('',"End Point",'Location','southeast')
  78. figure(5)
  79. plot(tt1*tscale/3600,hy,'-','linewidth',2);grid on;xlabel('time(h)');ylabel('h_y');
  80. hold on
  81. scatter(tt1(end)*tscale/3600,hy(end),200,"pentagram",'filled');
  82. legend('',"End Point",'Location','southeast')
  83. figure(6)
  84. plot(tt1*tscale/3600,L,'-','linewidth',2);grid on;xlabel('time(h)');ylabel('L(rad)');
  85. hold on
  86. scatter(tt1(end)*tscale/3600,L(end),200,"pentagram",'filled');
  87. legend('',"End Point",'Location','southeast')
  88. %% 绘制轨道
  89. figure(7)
  90. z1 = plot3(X_save(1,:)/1000,X_save(2,:)/1000,X_save(3,:)/1000,'r--','linewidth',1.5);hold on;
  91. z2 = plot3(X_save(1,1)/1000,X_save(2,1)/1000,X_save(3,1)/1000,'b.','MarkerSize',30);hold on;
  92. z3 = plot3(X_save(1,end)/1000,X_save(2,end)/1000,X_save(3,end)/1000,'k.','MarkerSize',30);hold on;
  93. axis equal;
  94. [x, y, z] = sphere(100);
  95. x = Re * x / 1000;
  96. y = Re * y / 1000;
  97. z = Re * z / 1000;
  98. surf(x, y, z);
  99. legend([z1,z2,z3],{'transfer orbit','Initial point','End point'});
  100. % legend([z1,z2,z3,z4],{'transfer orbit','Initial point','Target point','Engine shutdown point'});
  101. xlabel('x(km)');ylabel('y(km)');zlabel('z(km)');grid on;
  102. %% 卫星到地心的距离
  103. figure(8)
  104. plot(tt1*tscale/3600,sqrt(X_save(1,:).^2+X_save(2,:).^2+X_save(3,:).^2)/1000,'b-','linewidth',2);hold on;
  105. plot(tt1*tscale/3600,Re*ones(size(tt1))/1000,'r-','linewidth',2);hold on;
  106. plot(tt1*tscale/3600,(Re+100e3)*ones(size(tt1))/1000,'k--','linewidth',2);hold on;
  107. xlabel('time(h)');ylabel('r(km)');grid on;
  108. legend('Transfer vector diameter','Earth radius','Karman line');
  109. %% 推力方向
  110. figure(9)
  111. thrust_dire = zeros(3,size(tt1,1));
  112. for ii = 1:size(tt1,1)
  113. thrust_dire(:,ii) = thrust_direction_trans(xx1(ii,1:13), Environment_Param);
  114. end
  115. plot(tt1*tscale/3600,thrust_dire(1,:),'b-o','LineWidth',2,'markersize',3);hold on
  116. plot(tt1*tscale/3600,thrust_dire(2,:),'r-.','LineWidth',2);hold on
  117. plot(tt1*tscale/3600,thrust_dire(3,:),'-','LineWidth',2);hold on
  118. grid on;
  119. legend('axis-x','axis-y','axis-z');
  120. figure(10)
  121. % 第一个子图
  122. subplot(3,1,1);
  123. plot(tt1*tscale/3600,thrust_dire(1,:),'LineWidth',3);
  124. xlabel('time(h)');
  125. ylabel('T_x');
  126. grid on;
  127. ylim([-1,1])
  128. % 第二个子图
  129. subplot(3,1,2);
  130. plot(tt1*tscale/3600,thrust_dire(2,:),'LineWidth',3);
  131. grid on;
  132. xlabel('time(h)');
  133. ylabel('T_y');
  134. ylim([-1,1])
  135. % 第三个子图
  136. subplot(3,1,3);
  137. plot(tt1*tscale/3600,thrust_dire(3,:),'LineWidth',3);
  138. grid on;
  139. xlabel('time(h)');
  140. ylabel('T_z');
  141. ylim([-1,1])
  142. %% 转移时间
  143. figure(11)
  144. T_f = 2*pi*sqrt(a_f^3/3.9802e+14)/3600; % Terminal orbit period (h)
  145. trans_time = Read(:,10)* 1000 * tscale/3600; % time of engine turning on
  146. % plot(Read(:,3),trans_time,'LineWidth',2)
  147. scatter(Read(:,3),trans_time,'LineWidth',2)
  148. grid on
  149. xlabel('\kappa')
  150. ylabel('t_f(h)')
  151. title('轨道转移时间随\kappa的变化')
  152. %% kappa的变化
  153. figure(12)
  154. plot(Read(:,3),'-o','LineWidth',2,'MarkerSize',2)
  155. grid on
  156. ylabel('\kappa')
  157. xlabel('iteration times')
  158. title('\kappa随迭代次数的变化')
  159. %% 不同的sigma对应的kappa变化
  160. figure(13)
  161. line_styles = {'-', '-', '-', '-.', '-.', '-.'};
  162. markers = {'o', 's', '^', 'd', 'v', '*'};
  163. col = [1,0.5,0.1];
  164. d_col = [0,0.4,0.4];
  165. colors = [col;col;col;col;col;col;]; % 使用 MATLAB 内置的颜色映射,您也可以使用其他颜色映射或自定义RGB值
  166. colors = linspace(0,1,6)'*d_col + colors;
  167. for i = 2
  168. name = ['.//data//data-',int2str(i*100),'.txt'];
  169. data_read = readmatrix(name);
  170. XL = linspace(0, 1, length(data_read(:,3)));
  171. plot(XL, data_read(:,3), 'LineWidth', 2, 'LineStyle', line_styles{i-1}, 'Marker', markers{i-1}, 'Color', colors(i-1, :),'MarkerSize',6)
  172. hold on
  173. end
  174. grid on
  175. legend('\sigma_{max}=200','\sigma_{max}=300','\sigma_{max}=400','\sigma_{max}=500','\sigma_{max}=600','\sigma_{max}=700','Location','best')
  176. ylabel('\kappa')
  177. %% 过程中随kappa变化推力方向的变化
  178. figure(14)
  179. clear thrust_dire
  180. % 第一个子图
  181. ref = [1,4,11,27];
  182. name = ['.//data//data-',int2str(200),'.txt'];
  183. data_read = readmatrix(name);
  184. line_width = 1.5;
  185. marker_size = 4;
  186. for i = 1:4
  187. x0 = data_read(ref(i),4:10);
  188. tf = x0(7);
  189. state0 = zeros(26,1);
  190. state0(1:13) = [P0 ex0 ey0 hx0 hy0 L0 x0(1) x0(2) x0(3) x0(4) x0(5) x0(6) m0 ]';
  191. timespan = [0,tf*1000];
  192. options = odeset('RelTol',3e-14,'AbsTol',1e-14);
  193. % [tt1,xx1] = ode113(@dynamicModel, timespan,state0,options,0,tf*1000);
  194. [tt1,xx1] = ode113(@dynamicModel_InverseGauss,timespan,state0,options,Mu, Lambda,tf*1000, Environment_Param);
  195. %各个值
  196. P = xx1(:,1)*Lscale;
  197. ex = xx1(:,2);
  198. ey = xx1(:,3);
  199. hx = xx1(:,4);
  200. hy = xx1(:,5);
  201. L = xx1(:,6);
  202. n = round(200*tf);
  203. thrust_dire = zeros(3,n);
  204. for ii = 1:n
  205. thrust_dire(:,ii) = thrust_direction_trans(xx1(ii,1:13), Environment_Param);
  206. end
  207. subplot(3,1,1);
  208. plot(tt1(1:n)*tscale/3600,thrust_dire(1,:), 'LineWidth', line_width, 'LineStyle', line_styles{i}, 'Marker', markers{i}, 'Color', colors(i, :),'MarkerSize',marker_size);
  209. xlabel('time(h)');
  210. ylabel('T_x');
  211. hold on;grid on;
  212. legend('\kappa=0','\kappa=0.55','\kappa=0.86','\kappa=1')
  213. % 第二个子图
  214. subplot(3,1,2);
  215. plot(tt1(1:n)*tscale/3600,thrust_dire(2,:), 'LineWidth',line_width,'LineStyle', line_styles{i}, 'Marker', markers{i}, 'Color', colors(i, :),'MarkerSize',marker_size);
  216. hold on;grid on;
  217. xlabel('time(h)');
  218. ylabel('T_y');
  219. legend('\kappa=0','\kappa=0.55','\kappa=0.86','\kappa=1')
  220. % 第三个子图
  221. subplot(3,1,3);
  222. plot(tt1(1:n)*tscale/3600,thrust_dire(3,:), 'LineWidth',line_width, 'LineStyle', line_styles{i}, 'Marker', markers{i}, 'Color', colors(i, :),'MarkerSize',marker_size);
  223. hold on;grid on;
  224. xlabel('time(h)');
  225. ylabel('T_z');
  226. legend('\kappa=0','\kappa=0.55','\kappa=0.86','\kappa=1')
  227. end