% matlab script to test efficiency of
% Euler's method, classical Runge-Kutta, and ode45
% on Arenstorf orbit problem close all
clear all % these are variables we would like the right-hand function to "see"
% without actually passing them as arguments
global mu muHat % set normalized masses
mu = 0.012277471;
muHat = 1 - mu; % set time span of integration
t0 = 0;
tf = 17.1; % set initial conditions
u1 = 0.994;
u2 = 0;
u1Dot = 0;
u2Dot = -2.00158510637908252240537862224; % pack into vector y0
y0 = [u1 u2 u1Dot u2Dot]'; % set the name of the function to compute the right-hand side
f = 'arenstorf';
disp(['The ' f ' problem'])
disp(' ') % begin with Euler's method
disp('Experiments with Euler''s method.') % "logical" variable to end given phase (Euler, Runge-Kutta)
iMore = 1; while (iMore == 1),
% prompt user for number of steps
nSteps = input('Please enter the number of steps to take: ');
% set up array to store solution
y = zeros(length(y0),nSteps+1);
h = (tf-t0)/nSteps;
t = linspace(t0,tf,nSteps+1);
y(:,1) = y0;
tic
for i=1:nSteps,
y(:,i+1) = y(:,i) + h*feval(f,t(i),y(:,i));
end
toc
plot(y(1,:),y(2,:))
iMore = input('Do you wish to repeat with Euler''s method? (1=yes,0=no) ');
disp(' ')
end close all
% now investigate classical Runge-Kutta
disp('Experiments with classical Runge-Kutta method.') iMore = 1; while (iMore == 1),
% prompt user for number of steps
nSteps = input('Please enter the number of steps to take: ');
% set up array to store solution
y = zeros(length(y0),nSteps+1);
h = (tf-t0)/nSteps;
t = linspace(t0,tf,nSteps+1);
y(:,1) = y0;
tic
for i=1:nSteps,
K1 = feval(f,t(i),y(:,i));
K2 = feval(f,t(i)+h/2,y(:,i)+h*K1/2);
K3 = feval(f,t(i)+h/2,y(:,i)+h*K2/2);
K4 = feval(f,t(i+1),y(:,i)+h*K3);
y(:,i+1) = y(:,i) + h*(K1+2*(K2+K3)+K4)/6;
end
toc
plot(y(1,:),y(2,:))
iMore = input('Do you wish to repeat with classical RK? (1=yes,0=no) ');
disp(' ')
end
close all % finally use ode45
disp('Solving problem with ode45 ... ') % try with and without options in call to ode45
options = odeset('RelTol',1e-4); tic
[t,y] = ode45(f,[t0 tf],y0,options);
toc
plot(y(:,1),y(:,2)) % from Wikipedia about the Arenstorf orbit % Richard F. Arenstorf is an American mathematician who discovered a
% stable orbit between the Earth and the Moon, called an Arenstorf
% Orbit, which was the basis of the orbit used by the Apollo Program
% for going to the Moon. % The Arenstorf Orbit % While the orbit of a satellite around the Sun was empirically
% discovered by Kepler and theoretically proven by Newton to be an
% ellipse, at the time when the United States was interested in going
% to the Moon, there was no such solution known for the shape of a
% satellite orbiting regularly around two objects, such as a
% spacecraft going between the Earth and the Moon. This is a special
% case of the infamous Three Body Problem, for which a general
% analytical solution is not known because of its complexity of
% solving the effect of three bodies which all pull on each other
% while moving, a total of six interactions. However the case of an
% Earth-Moon satellite can be simplified to four interactions, because
% although the three objects gravitationally all pull on each other,
% the effect of the spacecraft's gravity upon the motion of the vastly
% more massive Earth and Moon is practically non-existent. Arenstorf
% found a stable orbit for a spacecraft orbiting between the Earth and
% Moon, shaped like an '8' with the Earth or Moon located inside each
% loop of the '8'. This orbit is the basis of a path going to the Moon
% from the Earth, such as the United States Apollo program. For a
% permanent presence on the Moon, it would be the path of what
% Arenstorf calls a 'Space Bus', a ferry which could regularly orbit
% supplies and people between the Earth and Moon without directly
% expending fuel. By staying on the Arenstorf orbit, lunar astronauts
% automatically return back to Earth. Before leaving NASA at the first
% Moon Landing, Arenstorf mapped out an emergency rescue orbit, which
% was used in the Apollo 13 incident, in which a catastrophic
% malfunction forced aborting the Moon landing, but the astronauts
% ultimately returned safely to Earth without a major course
% adjustment.

Matlab Euler's method的更多相关文章

  1. Matlab The Bisection Method

    MATLAB语言 function y=f(x) y=f(x); %函数f(t)的表达式 i=0; %二分次数记数 a=a; %求根区间左端 b=b; %求根区间右端 fa=f(a); %计算f(a) ...

  2. Matlab Newton‘s method

    定义函数 function y=f(x) y=f(x).%函数f(x)的表达式 end function z=h(x) z=h(x).%函数h(x)的表达式 end 主程序 x=X;%迭代初值 i=0 ...

  3. MATLAB曲面插值及交叉验证

    在离散数据的基础上补插连续函数,使得这条连续曲线通过全部给定的离散数据点.插值是离散函数逼近的重要方法,利用它可通过函数在有限个点处的取值状况,估算出函数在其他点处的近似值.曲面插值是对三维数据进行离 ...

  4. Matlab中的一些小技巧

    (转于它处,仅供参考) 1.. Ctrl+C 中断正在执行的操作 如果程序不小心进入死循环,或者计算时间太长,可以在命令窗口中使用Ctrl+c来中断.MATLAB这时可能正疲于应付,响应会有些滞后. ...

  5. Finite Difference Method with Mathematica

    Euler's method

  6. Matlab 之meshgrid, interp, griddata 用法和实例

    http://blog.sina.com.cn/s/blog_67f37e760101bu4e.html 实例结果http://wenku.baidu.com/link?url=SiGsFZIxuS1 ...

  7. MATLAB学习之内存溢出的管理方法

    今天用Matlab跑程序,由于数据量太大,又出现 Out of memory. Type HELP MEMORY for your options.的问题.看到这篇文章非常实用,转过来方便查阅~ 用 ...

  8. Matlab 之meshgrid, interp, griddata 用法和实例(转)

    http://blog.sina.com.cn/s/blog_67f37e760101bu4e.html 实例结果http://wenku.baidu.com/link?url=SiGsFZIxuS1 ...

  9. 【转】Matlab使用过程中内存不足问题的总结

    使用matlab过程中经常会出现内存不足的问题,这里转载一篇来自http://blog.csdn.net/xiaojidan2011/article/details/8089532 的博文,解决这一问 ...

随机推荐

  1. 卷积(转自wiki百科)

    维基百科,自由的百科全书 图示两个方形脉冲波的卷积.其中函数 "g" 首先对  反射,接着平移 "t" ,成为  .那么重叠部份的面积就相当于 "t& ...

  2. Django Template 进阶

    回顾: Variables {{ var }} {{ dict.key }} {{ var.attr }} {{ var.method }} {{ varindex }} Filter {{ list ...

  3. java 项目的路径详情

    title: 项目下的路径问题tags:grammar_cjkRuby: true--- 在javaee的项目中,存取文件,解析xml和properties文件,以及项目中的文件,都需要获取路径,常用 ...

  4. XCode 无法识别设备

    XCode 取消Unpair Device 后不能读取设备 1:退出XCode 2:断开设备连接 3:在终端执行‘sudo pkill usbmuxd’ 4:重启XCode 5:连接设备即可

  5. 多核CPU配合负载均衡可以这样用,为老板省点钱

    负载均衡作为一个处理高并发,大流量的访问的业务场景,已经几乎是常识性的知识了. 而本文的意义在于需求:由于大流量请求,导致服务无法正常响应,在不增加购买机器成本的场景下,如何提高服务器的业务处理能力? ...

  6. Python常用模块—— Colorama模块

    简介 Python的Colorama模块,可以跨多终端,显示字体不同的颜色和背景,只需要导入colorama模块即可,不用再每次都像linux一样指定颜色. 1. 安装colorama模块 pip i ...

  7. Python基础教程(第3版) 笔记(三)

    1.9.1让脚本像普通程序一样在UNIX中运行脚本,只需将下面的代码作为脚本的第一行, 就可在UNIX中轻松运行脚本: #!/usr/bin/env python 要像普通程序一样运行脚本,还必须将其 ...

  8. 音频标签化3:igor-8m项目的训练、评估与测试

    上一节介绍了youtube-8m项目,这个项目以youtube-8m dataset(简称8m-dataset)样本集为基础,进行训练.评估与测试.youtube-8m设计用于视频特征样本,但实际也适 ...

  9. MongoDB 系列文章

    MongoDB 系列文章 本文的内容是基于 MongoDB 4.0 的. 参考于 MongoDB 4.0 官方文档. 搭建 MongoDB从搭建到优化 MongoDB-副本集搭建与管理 管理 Mong ...

  10. 这次聊聊Promise对象

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由前端林子发表于云+社区专栏 Promise是CommonJS提出的一种规范,在ES6中已经原生支持Promise对象,非ES6环境可以 ...