Sie sind auf Seite 1von 9

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: ( given as: ( 2 ) 32 3C. )

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

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

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.

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

Fig 4: Using built-

N = 100.

Fig 5: Using Built-

, N =10,000.

Fig 6: Using built-

, N =100,000.

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 1.4414 (Fig 1) 1.4029 (Fig 3) 1.4108 (Fig 5) Built-In Function 1.4029 (Fig 2) 1.4221 (Fig 4) 1.4293 (Fig 6) Analytical Value

N = 100 N = 1000 N = 10,000

1.4203

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.

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

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

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

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

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

Das könnte Ihnen auch gefallen