% 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. jsp和html的区别

    html是超文本标记语言,只要有浏览器,就可以显示出来了. jsp是java server page就是在java服务器端的页面,需要通过jdk的编译才可以显示在客户端的浏览器上. 不仅如此,jsp还 ...

  2. 深入理解SpringCloud与微服务构建学习总结

    说明:用时 from 2018-11-16 to 2018-11-23 七天 0 放在前面   什么是微服务?   微服务是一个分布式系统.微服务架构的风格,就是将单一程序开发成一个微服务,每个微服务 ...

  3. 利用IP核设计高性能的计数器

    利用Quartus II的LPM_counter IP核进行设计(利用IP核设计可以迅速高效的完成产品的设计) 新建工程 调用IP核 创建一个新的IP核 选择LMP_COUNTER,语言类型,输出路径 ...

  4. Visual Studio中xml文件使用app.config、web.config等的智能提示的方法

    在.Net开发的过程中,有时我们需要使用Xml文件作为配置文件(基于某些情况的考虑),而不是app.config.web.config这种,但是我们在xml中配置时希望可以增加类似编辑app.conf ...

  5. cad2012卸载/安装失败/如何彻底卸载清除干净cad2012注册表和文件的方法

    cad2012提示安装未完成,某些产品无法安装该怎样解决呢?一些朋友在win7或者win10系统下安装cad2012失败提示cad2012安装未完成,某些产品无法安装,也有时候想重新安装cad2012 ...

  6. LeetCode:149_Max Points on a line | 寻找一条直线上最多点的数量 | Hard

    题目:Max Points on a line Given n points on a 2D plane, find the maximum number of points that lie on ...

  7. [EXP]Microsoft Windows 10 - XmlDocument Insecure Sharing Privilege Escalation

    Windows: XmlDocument Insecure Sharing Elevation of Privilege Platform: Windows (almost certainly ear ...

  8. Apache多站点配置(ubuntu)(原创)

      1,先进入Apaches2的目录下 cd /etc/apache2   2,进入sites-available中 cd sites-available vi 000-default.conf   ...

  9. Python日常实践(1)——SQL Prompt的Snippets批量整理

    引言 个人平时在写sql脚本的时候会使用到SQL Prompt这款插件,除了强大的智能提示和格式化sql语句功能,我还喜欢使用Snippets代码段功能.比如我们可以在查下分析器输入ssf后按Tab键 ...

  10. [,,].length等于几

    分别测试了谷歌.欧朋,火狐,QQ.搜狗,Edge,ie5.7.8.9.10.11 其中ie5,ie7,ie8得到的结果为3 其他均为2:如果最后一个逗号后面为空,则不识别最后一位