CEEMAE-M20-Homework3 (1)

pdf

School

University of California, Los Angeles *

*We aren’t endorsed by this school

Course

M20

Subject

Aerospace Engineering

Date

Feb 20, 2024

Type

pdf

Pages

3

Uploaded by BrigadierZebra1838

Report
Introduction to Computer Programming with MATLAB CEE/MAE M20 Homework #3 Due at 11:59 pm on Friday, April 22, 2022 Formatting Reminder: The submitted work must follow the naming convention listed below: LastName_UID_HW_03_report.pdf” LastName_UID_HW_03_main.m” Submit two separate files to the Bruin Learn course website: (1) a pdf-file of your written report and (2) a M ATLAB m-file written for the assignment. Use a switch statement to call for which problem to solve in your main script, i.e. do not submit two separate m-files for two problems. Remember to use good coding practices by keeping your script organized, choosing suitable variable names, and commenting where applicable. Your M ATLAB m-file should contain a few comment lines at the top to provide the name of the script, a brief description of the function of the script, and both your name and UID. Problem 1. The Three Species Problem Write a M ATLAB script that predicts the interaction between three groups of imaginary creatures X , Y , and Z competing for the same food. The populations of these three species are governed by the following Lotka-Volterra equations: d x d t D x 1 x 10 0:75xy 2x´ d y d t D 1:5y 1 y 5 0:5yx 1:5y´ d ´ d t D 1 ´ 2:5 1:5´x 0:5´y where x , y , and ´ are the populations per unit area of the species X , Y , and Z , respectively. 1. Write down the discretized equations for this problem based on the backward Euler method. Use the subscripts k and k C 1 to denote the known values at timestep k and the values to be determined at timestep k C 1 , respectively. 2. At t D 0 , the initial populations of x , y , and ´ are 10, 5, and 2.5, respectively. Use the backward Euler method with predictor-corrector method (using the tolerance tol D 10 12 ) to calculate the population of these three species up to t final D 20 a using the timestep size ĩt D 10 6 a. Print the time-varying populations (up to t final ) and the number of predictor- corrector iterations to the command window using the following format and 1 a time gaps (values shown are for illustration purposes only): 1
Time X Y Z it 0 10.00 5.00 2.50 1 0.59 1.43 0.74 4 2 0.26 1.29 0.65 2 3 0.12 1.29 0.65 3 : : : 3. Experiment with different initial population values (at least three sets), and observe the population-vs-time table for each. Using this guess-and-check approach, can you find a balancing point at which all these species coexist peacefully, or will one always crowd out the other two? 4. Use the tic and toc commands to time your script. What happens to the timing results when you use values of ĩt both larger and smaller than ĩt D 10 6 a? Be sure to include the timing results in your report. For a better accuracy of your timing results, run your script 10 times, disregard both the fastest and slowest time, and take the arithmetic mean of the remaining timing results as your averaged timing result for each computation. 5. Using the initial conditions listed in Part 2 and the timestep size ĩt D 10 6 a, which species survives? Which species survives when the initial conditions are kept the same, but the timestep increased to ĩt D 0:05 a? Which of the two outcomes reflects the more accurate interaction between these competing populations and why? Note that although you are encouraged to change the initial conditions and the timestep size ĩt to generate results for your report, please turn in the version of your script with the initial conditions listed in Part 2 and ĩt D 10 6 a. Problem 2. The Pocket Change Problem Write a M ATLAB script to answer the following question: What is the average number of coins you can expect to receive in your change after a cash transaction? To solve this problem, your script shall calculate the number of coins required to form all 100 cent amounts in the set f 0; 1; 2; :::; 99 g and then compute the arithmetic mean. Assume that all quantities of change are equally likely and that the denominations available are: Quarter = 25 Dime = 10 Nickel = 5 Penny = 1 Additionally, assume that all individual amounts are formed using the minimum number of coins, e.g. 58 cents require 2 quarters, 1 nickel, and 3 pennies for a total of 6 coins. 1. Use iterations to report the average number of coins using the following exact formatting: Average Number of Coins = 0.00 where 0.00 will be replaced by your answer formatted using ’%.2f’ . 2
2. Reconsider Part 1, and add a part to your script that recalculates the average number of coins using both the floor and the mod functions consecutively within your main loop. To be more precise, for each denomination, employ the floor function to find the number of coins and the mod function to determine the remaining amount. Do not include any other loop. 3. How does the average number of coins change if pennies are eliminated from the circula- tion? This would require rounding all prices to the nearest nickel, i.e. consider forming cent amounts in the set f 0; 5; 10; :::; 95 g . Can you come up with a simple mathematical argument or intuitive explanation to check your answer? Note that although you are encouraged to change the value of coins to generate results for your report, please turn in the version of your script using the denominations listed above forming the amounts in the set f 0; 1; 2; :::; 99 g . 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help