11
Asad Rauf CS 3200 Assignment 1 Report 1. Question 1: In the first part of this question the forward Euler method was used in order to calculate the final temperature of the coffee cup. Using this method, the solution (the temperature of the cup with time) using 6 different step sizes was plotted. Two plots were made, each containing three solutions (Fig1, Fig 2). The curves were very close to overlapping so it was easier to see the differences when zoomed in (Fig 3). In this method, the larger the step size h is, the larger the resulting error is. Using this method and a step size of .125 seconds, the temperature of the coffee after 2 minutes was found to be 32.2 °C. The analytical solution for this equation was found by solving the differential equation: dT c dt =−r ( T c T s ) given as: T c =T s + ( T Cinitial T s ) ∙e 1∙r∙t °C.

Euler's Method Scientific Computing

Embed Size (px)

DESCRIPTION

A scientific computing example in how different Euler's Method would appear.

Citation preview

Page 1: Euler's Method Scientific Computing

Asad RaufCS 3200Assignment 1 Report

1. Question 1: In the first part of this question the forward Euler method was used in order to calculate the final temperature of the coffee cup. Using this method, the solution (the

temperature of the cup with time) using 6 different step sizes was plotted. Two plots were made, each containing three solutions (Fig1, Fig 2). The curves were very close to

overlapping so it was easier to see the differences when zoomed in (Fig 3). In this method, the larger the step size h is, the larger the resulting error is. Using this method and a step size of .125 seconds, the temperature of the coffee after 2 minutes was found

to be 32.2 °C. The analytical solution for this equation was found by solving the differential equation:

d T c

dt=−r (T c−T s )given as:

T c=T s+(T Cinitial−T s ) ∙ e−1 ∙r ∙ t°C.

Fig 1: Solutions Coffee cup problem w/ step size 4, 2, and 1 seconds.

Page 2: Euler's Method Scientific Computing

Fig 2: Solutions Coffee cup problem w/ step size 0.5, 0.25, and 0.125 seconds.

Fig 3: Zoomed in version of Figure 2 (step size 0.5, 0.25, and 0.125 seconds).

Page 3: Euler's Method Scientific Computing

2. Question 2: The random number generator used for this problem uses the linear congruent method. For N = 100, the parameters were chosen as; a = 16807, c = 0, M = 1361, and the initial value was chosen as 1. The first 100 values were chosen for the data set and plotted (Fig 1). A similar process was used for N = 10,000 (Fig 2) and N = 100,000 (Fig 3). The rand function was used to generate similar sets of random numbers and they were also plotted (Fig 4-6). Comparing the two plots of the same sample sizes (one from each method used) showed that the plots looked very similar. In both sets of 100,000, the entire plot was nearly filled.

Fig 1: Linear Congruent Method, N =100

Fig 2: Linear Congruent Method, N = 10,000.

Page 4: Euler's Method Scientific Computing

Fig 3: Linear Congruent Method, N = 100,000.

Fig 4: Using built-in “Rand” function N = 100.

Page 5: Euler's Method Scientific Computing

Fig 5: Using Built-in “Rand” function, N =10,000.

Fig 6: Using built-in “Rand” function, N =100,000.

Page 6: Euler's Method Scientific Computing

3. Question 3: For this question we used a similar method to what was used before (Linear Congruent Method, LCM) to generate X and Y coordinates. The X coordinates were created to be located 0 and 1, and the Y coordinates were created so that they were all located between 0 and the maximum value found in the function. In each instance (N = 100, N = 1000, and N = 10,000) the values are plotted concurrently onto a plot of the function. The program then counts how many of these points are above the curve. The area of the plotting plane (which is equal to the maximum value of the function multiplied by 1) and the fraction of points under the curve is used to estimate the area above and below the function. The same method was used again, but with the coordinates being generated using the build-in function in MATLAB. The table below summarizes the results.

Linear Congruent

Built-In Function

Analytical Value

N = 100 1.4414 (Fig 1)

1.4029(Fig 2)

1.4203N = 1000 1.4029

(Fig 3)1.4221(Fig 4)

N = 10,000 1.4108(Fig 5)

1.4293(Fig 6)

From the results above and the plots of this process (Fig 1-6) we can see that the Linear Congruent Method and the build in function both gave similar results. The value obtained using this method and the built-in function both gave values that were both hovering around the correct answer.

Fig 1: Function and Random Points using LCM, N =100.

Page 7: Euler's Method Scientific Computing

Fig 2: Function and Random points using Rand Function, N =100.

Fig 3: Function and Random Points using LCM, N =1000.

Page 8: Euler's Method Scientific Computing

Fig 4: Function and Random Points using built-in function, N = 1000.

Fig 5: Function and Random Points using LCM, N =10,000.

Page 9: Euler's Method Scientific Computing

Fig 6: Function and Random Points using built-in function, N = 10,000.