% 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. 基于UML的毕业选题系统建模研究

    一.基本信息 标题:基于UML的毕业选题系统建模研究 时间:2018 出版源:电脑迷 领域分类:UML建模技术 二.研究背景 问题定义:为了加强学生设计分析开发软件的相关能力,有效避免结构化模型存在的 ...

  2. 20155326刘美岑《网络对抗》Exp5 MSF基础应用

    基础问题回答 解释exploit,payload,encode是什么: exploit:就是一个简单的攻击指令,在配置完成之后下发攻击命令. payload:是攻击载荷,是我们在攻击过程中真正用到的部 ...

  3. bash编程-Shell变量

    bash中,所有变量的值默认均为字符串. 1. 变量操作 调用变量 $变量 查看变量(所有类型) set 删除变量 unset 变量 2. 变量分类 2.1 自定义变量 自定义变量仅对当前Shell有 ...

  4. WITH RECOMPILE和OPTION(RECOMPILE)区别

    在考虑重编译T-SQL(或者存储过程)的时候,有两种方式可以实现强制重编译(前提是忽略导致重编译的其他因素的情况下,比如重建索引,更新统计信息等等), 一是基于WITH RECOMPILE的存储过程级 ...

  5. python 使用多线程进行并发编程/互斥锁的使用

    import threading import time """ python的thread模块是比较底层的模块,python的threading模块是对thread做了 ...

  6. docker 容器时间和系统时间不一致

    docker cp /etc/localtime 容器名:/etc/localtime cp /etc/localtime 24fe94504424:/etc/localtime date -s 09 ...

  7. 一个关于margin-top的问题

    两个 此时内部div的样式为 当我把margin选中 如图所示: 我想要的效果是子div离父div有一个20px的间隙,但显然现在不是我想要的结果, 然后就开始查资料: 这个“问题”……它是CSS2. ...

  8. linux下配置nginx负载均衡例子

    准备2台虚拟机: 分别在两个虚拟机上安装tomcat,并在服务器A安装nginx,其中nginx端口设置为了 70. 服务器A的tomcat安装目录: 服务器B的tomcat安装目录: 服务器A的ng ...

  9. Runtime 自动化归档

    Runtime的使用 (id)initWithCoder:(NSCoder *)decoder { if (self = [super init]) { unsigned ; Ivar *ivars ...

  10. antd tree组件文件名换行 + 点击展开时,自动收起同级其他展开目录

    1.在项目中用 antd的tree组件的时候,遇到两个问题 1.文件名太长的话 会超出容器 很难看,解决方法如下 ` 引入css在global下设置 :global { .ant-tree li .a ...