User Tools

Site Tools


gibson:teaching:spring-2016:math445:lecture:timestepping

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gibson:teaching:spring-2016:math445:lecture:timestepping [2016/04/14 11:55]
gibson [Problem 3]
gibson:teaching:spring-2016:math445:lecture:timestepping [2016/04/14 18:23] (current)
gibson [Problem 4]
Line 81: Line 81:
  {{ :​gibson:​teaching:​spring-2016:​math445:​lecture:​cylinderpath1.png?​direct&​400 }}  {{ :​gibson:​teaching:​spring-2016:​math445:​lecture:​cylinderpath1.png?​direct&​400 }}
  
-Note that the computed ​trajectory is not very accurate, since we chose quite a large time step $\Delta t = 0.4$, and forward-Euler is only 1st-order accurate (error scales as $\Delta t$).+ 
 +Note that the trajectory ​computed here is not very accurate. The particle shouldexit the box at the same $y$ value it had when it entered. The problem is we chose quite a large time step $\Delta t = 0.4$, and forward-Euler is only 1st-order accurate (error scales as $\Delta t$). In the next problem, we'll reduce the time step to $\Delta t = 0.01$ and get a more accurate solution --though still not as good as the 4th-order accurate ''​ode45''​ function. 
 ---- ----
  
 ====Problem 2==== ====Problem 2====
  
-Write Matlab code that plots the //path// of the particle as a red curved line. To do this wee need to save the sequence of $\vec{x}$ values in a matrix, and then plot the rows of that matrix as a line.+Write Matlab code that plots the //path// of the particle as a red curved line. To do this we need to save the sequence of $\vec{x}$ values in a matrix, and then plot the rows of that matrix as a line.
  
 <code matlab> <code matlab>
Line 127: Line 129:
 axis equal axis equal
 axis tight axis tight
-xlim([-xmax,xmax]) +xlim([-3,3]) 
-ylim([-ymax,ymax])+ylim([-2,2])
 </​code>​ </​code>​
  
Line 170: Line 172:
   x0 = [-2.8; y];                 % set initial position of particle   x0 = [-2.8; y];                 % set initial position of particle
  
-  [t, x] = ode45(@v, [0 T], x0);  % compute x(t) at given values of t+  [t, x] = ode45(@v, [0 T], x0);  % compute x(t) over range 0 <= <= T
  
   plot(x(:,​1),​ x(:,2), '​r-'​); ​    % plot the path   plot(x(:,​1),​ x(:,2), '​r-'​); ​    % plot the path
gibson/teaching/spring-2016/math445/lecture/timestepping.1460660158.txt.gz · Last modified: 2016/04/14 11:55 by gibson