Solved–Programming Assignment 1– Solution

$35.00 $24.00

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. 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…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)
  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.

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

    1. 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:

    1. 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.

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

    1. 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.

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

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

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

    1. 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.

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

  1. 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.

5. 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