% 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. ubuntu下chrome浏览器安装flash插件(pepperflashplugin-nonfree)

    安装前说明: ubuntu的Google 已经不能使用Adobe Flash了,需要用PepperFlashPlayer来替代 Adobe Flash才行. 安装步骤: 1.安装pepperflash ...

  2. 背水一战 Windows 10 (83) - 用户和账号: 数据账号的添加和管理, OAuth 2.0 验证

    [源码下载] 背水一战 Windows 10 (83) - 用户和账号: 数据账号的添加和管理, OAuth 2.0 验证 作者:webabcd 介绍背水一战 Windows 10 之 用户和账号 数 ...

  3. 《http权威指南》读书笔记1

    概述 最近对http很感兴趣,于是开始看<http权威指南>.别人都说这本书有点老了,而且内容太多.我个人觉得这本书写的太好了,非常长知识,让你知道关于http的很多概念,不仅告诉你怎么做 ...

  4. Java学习笔记35(异常)

    代码在运行中发生的问题就是异常 java中把多种异常封装多个类,当程序出现问题时候,就会创建异常类对象并且抛出相关信息 异常体系: Throwable类是Java中所有错误或异常的父类 Throwab ...

  5. Swift5 语言指南(十三) 方法

    方法是与特定类型相关联的函数.类,结构和枚举都可以定义实例方法,这些方法封装了用于处理给定类型的实例的特定任务和功能.类,结构和枚举也可以定义类型方法,它们与类型本身相关联.类型方法类似于Object ...

  6. Maven - 实例-5-依赖冲突

    避免依赖冲突的原则 如果项目中的pom.xml没有指定依赖的信息,而是通过继承来引用依赖,则很有可能发生继承同一个依赖的多个版本,从而产生依赖冲突. Maven通过如下两个原则来避免依赖冲突: 1- ...

  7. Java开发技术大揭底——让你认知自己技术上的缺陷,成为架构师

    一.分布式架构体系 分布式怎么来的.传统的电信.银行业,当业务量大了之后,普通服务器CPU/IO/网络到了100%,请求太慢怎么办?最直接的做法,升级硬件,反正也不缺钱,IBM小型机,大型机,采购了堆 ...

  8. C# signtool error:no certificates were found that met all the given criteria 错误解决方案

    程序运行时报错:signtool error:no certificates were found that met all the given criteria (汉译:符号工具错误:没有找到符合所 ...

  9. 如何把开源项目发布到Jcenter

    转载自:https://www.jianshu.com/p/f66972f0607a 首先我们应该注册一个JFrog Bintray的账号 Jfrog Bintray官网 这里我们可以注意到那个绿色的 ...

  10. C#对象内部属性排序测试

    构建对象: class SortGrid { int indexI; int indexJ; public SortGrid(int x, int y) { indexI = x; indexJ = ...