- Parent Category: Programming Assignments' Solutions
We Helped With This MATLAB Programming Homework: Have A Similar One?
|More Info||Matlab Question Solver|
Algorithms and Programming for SE
Unique Course ID:
• Observe the honor code and exclusively provide your own work
• Write your class ID on the upper right corner of every page (1 bonus point)
• Due Date for TritonED Submission: Wednesday, June 14th, 14:29pm
• Hardcopy Due: Wednesday, June 14th, 11:30-14:29, SME 342D
Problem 1: Unit Selection
Problem 1: Best Plot
Problem 3: GUI
Computer Aided Design (CAD) is a fundamental step in day-to-day structural engineering work. Commonly a design will begin with a preliminary sketch, followed by a more detailed drawing. For this problem, you will develop program that creates and draws a cable-stayed bridge in accordance with a set of user definable parameters.
(a) Write a function called BridgePlot that plots a bridge in accordance with the provided parameters
function  = BridgePlot(H,L,b,h,n)
H: tower height [m] L: deck length [m] b: deck height [m] h: attachment height [m]
n: number of cable anchors
Your function may plot the cables either as a continuous line (be mindful of the order!) or as individual lines. The tower and deck can be plotted afterwards as two separate lines. For clarity consider using different line colors and thicknesses for the deck, tower and cables. Make sure to provide proper labels and annotations that satisfy engineering demands. You may assume even anchor spacing.
Note: It is a good idea to write and thoroughly test this function first before working on the next part of this assignment.
(b) Write a GUI called BridgeBuilder that provides the user with sliders to control the above parameters. It should be clear to the user what type of units are being used. Remember to fool-proof your GUI. For example, the minimum attachment height cannot exceed your tower height!
• 1 bonus point if your GUI allows the user to toggle between [m] and [ft] as the units of choice
• 2 bonus points for the program that most closely mimics the figure provided above.
Arrays, loops as well as indexing operations for value assignment and lookup are everywhere. In this problem, you will refine and apply your programming skills in these areas.
a) Write the following function
function res = simulateDiceRolls(numDice, numRolls)
For this function you will use the 'randi' function to simulate throwing random rolls of 6-sided dice numRolls times. Each roll can be with a handful of dice ranging from 1-10. The beginning of your function should check that the argument numDice is in the range of [1:10] and that numRolls is the range of [1:10,000]. If either of these limits are exceeded print an error message.
Keep track of the number of times a particular score in rolled in the return value 'res' which should have length 6*numDice where each entry will be an integer containing the number of times a score was rolled matching the index of that entry. For example, if numDice=2, numRolls=3, and the simulator rolls a [1,1] and a [4,6], and a [5,5], res will look like this: [0,1,0,0,0,0,0,0,0,2,0,0]
Finally plot the resulting distribution of rolls inside the function with plot(res) and add appropriate labels and limits to the x and y axis. Make sure the y axis ranges from 0 to max(res) and the x axis ranges from numDice to 6*numDice.
b) Write the following function
function res = incrementRoll(roll)
This function will assist you in iterating through every possible combination of dice rolls by taking a roll and returning the next in the following series. It should support any length of vector 'roll' greater than or equal to 10. No error checking is necessary, not even for the end of the series. The series should mimic that of a car odometer, rolling over the next digit when the previous digit exceeds 6.
Here are some samples of the series for 3 dice:
input result [1,1,1] > [2,1,1]
[6,1,1] > [1,2,1]
[6,6,5] > [1,1,6]
[5,6,6] > [6,6,6]
[6,6,6] > [1,1,7]
Do not worry about the last entry exceeding 6 as you will be careful not to call incrementRoll past the end of the series in the next part.
c) Write the following function
function res = calculateDiceStats(numDice)
Start by copying your function from part A and modify it to use your incrementRoll function to loop through all possible combinations of rolls instead of randomly generating the rolls. The total rolls it should calculate should be 6^numDice. Start with an initial roll of [1,1,1......] and increment to [6,6,......] with the incrementRoll function.
As in part A, check that numDice is between 1 and 10 and plot the distribution of possible rolls after calculating res. Your resulting plots should be similar to the randomly generated distributions but smooth instead.
Problem 3: Use a stochastic iterative process to create a Sierpinski Pentagon
Nature-inspired materials and structures have received a lot of attention over the past couple of years, drawing from a field that frequently is referred to as biomimicry or biomimetics. Wikipedia provides the following motivation. “Over the last 3.6 billion years, nature has gone through a process of trial and error to refine the living organisms, processes, and materials on planet Earth. The emerging field of biomimetics has given rise to new technologies created from biologically inspired engineering at both the macro scale and nanoscale levels. Biomimetics is not a new idea. Humans have been looking at nature for answers to both complex and simple problems throughout our existence. Nature has solved many of today's engineering problems such as hydrophobicity, wind resistance, self-assembly, and harnessing solar energy through the evolutionary mechanics of selective advantages.” The
mathematics and computational science domains in turn have studied chaos theory, among others, as a means to capture the mathematical beauty found in nature and to use it to model other systems. Chaos theory uses a stochastic (i.e. random) iterative process, to create fractal geometry and in this problem, you will develop a function, which generates the data points for specific fractals using chaos theory, through a process also referred to a chaos game. Write the following function:
function  = SierpinskiPentagon(n) where n is the number of times to run the algorithm
The algorithm for the construction of a Sierpinski Pentagon is given by:
(a) Define the five corners of the pentagon with center point [0,0] and label them p1, p2, p3, p4, or p5
(b) Plot the outline of the pentagon
(c) Select any one of the corner points as the starting point, making it your “current position”, e.g.
current_position = [0,1]
(d) Randomly select one of the five corner points, p1, p2, p3, p4, or p5
(e) Move a scaled distance r from your current position towards the selected point and make this your new current position
(f) Plot the new current position, aggregating points in the same plot as they are being computed.
(g) Repeat from step (d) for n times.
HINT: for the scaling factor (r), see the figure below.
• 2 point for a GUI allowing the user to change the value of n with a slider and a text field
Take-Home Exam Preparation
1. Create a directory named “final_yourclassid_lastname” at a location of your choice.
2. In this directory, create a file for each of the needed functions. As always, use the provided function names as the filename for your developed functions.
3. Copy your showMyCredentials.m file to the same directory and update it as needed.
Take-Home Exam Submission via TritonED:
1. Create a zip file containing the entire "final_yourclassid_lastname" directory. Do this by running your favorite zip tool from the directory where the "final_yourclassid_lastname" directory is located.
2. Name the zip archive "final_yourclassid_lastname.zip"
3. Submit only the .zip file
Submission via Hardcopy
To allow you to properly highlight your achievements and any extra credit work, we ask you to give us a hardcopy of all files, sorted in order of execution. Feel free to add annotations, graphs/plots or any other visuals that will allow you to showcase your work. As always, please place your unique personal class ID on the right, upper corner of the front page of the hardcopy. This identifier will be a number in the range of [001, number of enrolled students], which will allow for easier matching between your hardcopy and online submission.