<< Return to class page

Math 151 Lab 06 - 02/05/2018:

DUE: Wednesday, February 7, 2018 (by 4:00pm before class starts)

INSTRUCTIONS: Save this Matlab script with the filename LastName_Lab06.m (example: Lewis_Lab06.m). Complete each question (either in words or with Matlab code). When you are ready to have your assignment graded, choose the PUBLISH command from the file menu, and submit the resulting file to CANVAS.

Contents

#1

WRITE CODE BELOW:

Recall how to define anonymous functions from the lecture.

a) Define an anonymous function df1(x,y) = -y

b) Define an anonymous function df2(x,y) = 2*y/x

c) Define an anonymous function df3(x,y) = [10*(y(2)-y(1)); y(1)*(28-y(3))-y(2); y(1)*y(2)-8/3*y(3)]

NOTE: Use these for your 3 df functions for the next 3 problems.

------------------------------------------------------------------------

#2

WRITE CODE BELOW:

Step 1: Write code to solve the ODE given by f'(x)+f(x)=0 on the interval [0,5] with the initial condition f(0)=1. Use Euler's Method with dx=0.5.

Step 2: The exact solution is e^(-x). Plot e^(-x) and the solution you obtained in step 1 on the same plot. Use different colors for each function.

Step 3: Label your plot using the command 'legend'.

Step 4: Repeat steps 1-3 using with dx=0.1.

WRITE A COMMENT BELOW:

How accurate was your solution? Do you think making dx smaller will improve your solution?

------------------------------------------------------------------------

#3

WRITE CODE BELOW:

Step 1: Write code to solve the ODE given by xf'(x)-2f(x)=0 on the interval [1,5] where f(1)=0.5. Use the Midpoint Method with dx=0.5.

Step 2: The exact solution is 0.5 x^2. Plot the exact solution and your solution on the same plot. Use different colors for each function.

Step 3: Label your plot.

WRITE A COMMENT BELOW:

Does using the midpoint method on this problem seem more accurate than using Euler's method on the previous problem? Explain. Make sure you compare the plots with same dx value!

------------------------------------------------------------------------

#4

WRITE CODE BELOW:

Step 1: Write code to solve the system of ODEs given by the Lorenz system (the equation in 1c) on the interval [0,100] where f(1)=[10;10;10]. Use ODE45 for this.

Step 2: Use plot3 on each column of your solution vector (f(:,1), f(:,2), f(:,3)).

Step 3: Label your plot and enjoy some cool looking math!

Step 4: Repeat steps 1-3 with a new intial condition of f(1)=[100;100;100]

WRITE A COMMENT BELOW:

Does changing the inital condition from [10;10;10] to something like [100;100;100] change how your solution looks? Explain.

------------------------------------------------------------------------