Matlab Euler's method
% 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的更多相关文章
- 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) ...
- 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 ...
- MATLAB曲面插值及交叉验证
在离散数据的基础上补插连续函数,使得这条连续曲线通过全部给定的离散数据点.插值是离散函数逼近的重要方法,利用它可通过函数在有限个点处的取值状况,估算出函数在其他点处的近似值.曲面插值是对三维数据进行离 ...
- Matlab中的一些小技巧
(转于它处,仅供参考) 1.. Ctrl+C 中断正在执行的操作 如果程序不小心进入死循环,或者计算时间太长,可以在命令窗口中使用Ctrl+c来中断.MATLAB这时可能正疲于应付,响应会有些滞后. ...
- Finite Difference Method with Mathematica
Euler's method
- Matlab 之meshgrid, interp, griddata 用法和实例
http://blog.sina.com.cn/s/blog_67f37e760101bu4e.html 实例结果http://wenku.baidu.com/link?url=SiGsFZIxuS1 ...
- MATLAB学习之内存溢出的管理方法
今天用Matlab跑程序,由于数据量太大,又出现 Out of memory. Type HELP MEMORY for your options.的问题.看到这篇文章非常实用,转过来方便查阅~ 用 ...
- Matlab 之meshgrid, interp, griddata 用法和实例(转)
http://blog.sina.com.cn/s/blog_67f37e760101bu4e.html 实例结果http://wenku.baidu.com/link?url=SiGsFZIxuS1 ...
- 【转】Matlab使用过程中内存不足问题的总结
使用matlab过程中经常会出现内存不足的问题,这里转载一篇来自http://blog.csdn.net/xiaojidan2011/article/details/8089532 的博文,解决这一问 ...
随机推荐
- 消息中间件——kafka
1.1.1 什么是消息中间件 消息中间件利用高效可靠的消息传递机制进行平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息排队模型,它可以在分布式环境下扩展进程间的通信.对 ...
- dtb和dtc文件浅析
目录 dtb和dtc文件浅析 工具集 dts格式 dtb头部结构 dtb标识符 分析具体的文件 title: dtb和dtc文件浅析 date: 2019/4/25 20:09:38 toc: tru ...
- 7.ViewPagerIndicator
ViewPager指针项目,在使用ViewPager的时候能够指示ViewPager所在的位置,就像Google Play中切换的效果一样,还能使用在应用初始化的介绍页面</item> ...
- JavaScript实现多张图片上传功能
今天闲着没事,把之前的多张图片上传代码整理了下. 页面主要代码: <div class="upBox upBox2"> <div class="d1&q ...
- @RequestParam加不加的区别
感觉@撸码识途 https://www.cnblogs.com/tinyj/p/9786131.html 加上的情况: @RequestMapping("demo") public ...
- Spark Core
Spark Core DAG概念 有向无环图 Spark会根据用户提交的计算逻辑中的RDD的转换(变换方法)和动作(action方法)来生成RDD之间的依赖关系,同时 ...
- linux下配置nginx负载均衡例子
准备2台虚拟机: 分别在两个虚拟机上安装tomcat,并在服务器A安装nginx,其中nginx端口设置为了 70. 服务器A的tomcat安装目录: 服务器B的tomcat安装目录: 服务器A的ng ...
- 一款jq的计时器
举例子: http://files.cnblogs.com/Alandre/201201031633347950.rar
- 从零开始学 Web 之 移动Web(八)Less
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十九):服务消费(Ribbon、Feign)
技术背景 上一篇教程中,我们利用Consul注册中心,实现了服务的注册和发现功能,这一篇我们来聊聊服务的调用.单体应用中,代码可以直接依赖,在代码中直接调用即可,但在微服务架构是分布式架构,服务都运行 ...