Programming Assignment 1 Solution

$35.00 $29.05

You'll get a: . zip file solution, download link after Payment

Description

  1. Tutorial:Read pages 12-31 in the tutorial. Pay attention to for loops, functions, plotting, and di er-ential equations. Reproduce results as you read. Take advantage of the \help” command in Scilab.

 

  1. Basic coding: Using the command window, solve problem 1 of section 1.4 in the text using these steps.

 

  • Create a Scilab function for right hand side function f(t; y).

 

  • De ne variables y0; t0; tN; dt; t where

 

 

y0 = y(0); t0 = t(0); tN = end time; dt = t; t = a vector containing all time points:

 

  • Write a for loop which computes (forward) Euler’s method approximations using the above func-tion and variables. Store your solution in a new vector y which contains the Euler approximation at all time points.

 

  • Plot y against t to visualize your approximation solution solution.

 

  • Find the true solution. Add it to the approximate solution plot for comparison.

 

  1. Euler’s method:In SciNotes de ne a function called \Euler” for solving the general  rst order equation

 

dy = f(t; y);  y(0) = y0; 0   t   tN ;t = 1
   
dt N

 

You should use your work from the previous problem.

 

  • The inputs are \y0; t; f” as described in the previous problem.

 

  • The output of the function is \y”, the Euler’s method approximation.

 

  • Test your function on problems 1-4 in section 1.4 of the text with various choices of  t.

 

  • Reproduce the results in Tables 1.7/1.8 in the text. Use a matrix to store and print the results. Plot these two approximate solutions with the true solution.

 

  1. Instability and backwards Euler: In class we showed forward Euler is unstable when solving the sti

ODE

 

dy =  100y;  y(0) = 1:
dt
 

That is, t has to be very small otherwise forward Euler blows up.

 

  • Use forward Euler to solve this problem for 0 t 101with various choices of t. How small does t have to be to see convergence? Graph your numerical solutions with the true solution.

 

  • Backward Euler for any  rst order equation dydt= f(t; y) is given by

 

yn+1   yn = f(tn+1; yn+1):
t
 

Note that you need to solve an equation for yn+1 at each step. Implement backward Euler for this problem with various choices of t.

 

  1. Improving Euler: Averaging forward and backward Euler gives centered Euler’s method. That is,

 

(a) Forward Euler: yn+1  yn = fn

 

t

(b) Backward Euler: yn+1  yn = fn+1

 

t

(c) Centered Euler: yn+1  yn = 1 (fn + fn + 1)

 

t 2

 

Note, centered Euler is an implicit method (as was backward Euler). Implement centered Euler and compare it to backward Euler for the previous problem. Which is more accurate? Plot both solutions along with the true solution.

 

  1. (Bonus Problem!) Use Taylor series to  nd the rate of convergence of backward and centered Euler.

 

  1. (Bonus Problem!) Show stability requirements of centered Euler as done in class for forward and backward Euler.

 

 

1