90 likes | 204 Vues
This lecture focuses on advanced techniques for programming in scientific contexts using Mathematica and MATLAB. Topics include detailed reviews of Homework 4, integrations using NDSolve and FindRoot, as well as demonstrating the N-body planetary problem through Runge-Kutta numerical integration. Key features of real-time graphics output in MATLAB are discussed, with an emphasis on animation techniques and effective data visualization. This lecture serves as a foundation for understanding computational methods applicable to final projects.
E N D
12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room 54-618, tah@mit.edu Chris Hill, Room 54-1511, cnh@gulf.mit.edu Web page http://www-gpsg.mit.edu/~tah/12.010
Overview Today • Review some aspects of Homework 4 (Mathematica). • Look at formatting of question 1 • Look at FindRoot and NDSolve for Question 3. • Final Project: Examine Matlab N-body project to show: • methods Animation • Solution using odeXX differential equation solver in Matlab • End by looking at some graphics packages 12.010 Lec 20
Mathematica Homework • Question 1: Formatting output was tricky:The notebook 12.010_Lec20_Mathematica.nb gives examples for some solutions • Question 2: OK, features from 5.2 Mathematica used • Question 3: NDSolve was the way to solve this problem along with FindRoot 12.010 Lec 20
Final Project: • Example case for N-body problem: • N-body planetary problem that use Runge-Kutta numerical integration with variable step size. • Demonstrate basic use of this program (tar file on web site) • Graphics usage in gui-form: Basic methods can be used in your projects. 12.010 Lec 20
Graphics real-time output in Matlab • In Matlab: we can consider “real time” out put the results • When a plot is made you can set an “EraseMode” • Options are: • none — leaves all points on the screen • background — paints old points with background color. Erases old points but also erases any other information such as grid lines and text • xor — Exclusive or. Erases just the previously plotted points, leaves the background intact 12.010 Lec 20
Generating animated sequence with Matlab • Basic mode of use: • Plot first point keeping the graphics handle • p = plot3(x,y,z,’.’, ‘EraseMode’,’xor’); • Set the axis limits: (Need to think of values to use here. • axis([-100 100 -100 100 -100 100]); • hold on • Now generate the sequence of points • Loop over time steps, compute new x y z • set(p,’Xdata’,x,’Ydata’,y,’Zdata’,z) • Drawnow • These ideas were demonstrated in Matlab M-file 12.010 Lec 20
ODE Solvers • Use of ODE Solvers in Matlab (demonstrated in class) • Vector y is 2-d position and velocity (1:4). y0 = [0.0; 0.0; vx; vz]; [t,y,te,ye,ie] = ode23(@bacc,[0:1:tmax],y0,options); • The bacc routine computes accelerations. dy/dt is returned so that dy[1]=d(pos)/dt=y[3]; dy[2]=y[4]; and dy[3] and dy[4] are new accelerations function dy = bacc(t, y) % acc: Computes accelerations • Options sets ability to detect event such as hitting ground options = odeset('AbsTol',[terr 1 1 1],'Events','hit'); function [value,isterminal,direction] = hit(t,y) Value returns the height. • Look through Matlab help and use demo program 12.010 Lec 20
Graphics Programs • Basic data plotting programs: • There a number of programs which fall into this basic category: • KaleidaGraph — commercial program runs on PC and Mac (~$150) (web http://www.synergy.com) • Tecplot — Available on Athena (Unix and PC) ($1300) (web http://www.amtec.com/) • Grace -- Similar to KaleidaGraph available free for Unix systems. The old version is called xmgr. (http://plasma-gate.weizmann.ac.il/Grace/ • Demo of basic features of these types of programs 12.010 Lec 20
Summary • Looked at Mathematica homework solution • Example of 3-D Numerical integration Project • Graphics packages • Matlab homework due Thursday Dec 1. 12.010 Lec 20