June 21, 2016
finance | ENGR105 | Homework 3

Homework 3
Due by 9am 6/21/16. Submit 5 files.
Problem 1. In finance, many times you have estimates of how much expenses will cost and how much revenue will be brought in. However, it is very rare that you have those values ahead of time while making decisions. Each financial decision has a large amount of variability. To deal with this variability, financial advisers use tools to process the expected profit as well as the variance, if problems appear. A Monte Carlo simulation is one of those tools. Here you will create a Monte Carlo simulation as a basic financial model for decision making.
The most basic model of a company’s money flow is:
Net Profit = Sales Volume* (Selling Price – Unit cost) – Fixed costs
Imagine that you are working for Mathworks and trying to determine the profitability of producing the student version of Matlab. To produce the discs, you would have to pay for a new factory (FixedCosts=150000±1000 per month) as well as the cost of the disc/packaging/server usage/etc (UnitCost=10±4). If the selling price is set at $100 (SellingPrice=100) and you expect to sell 2000±200 copies per month (SalesVolume=2000±200), what is the likelihood that you would make a profit?
NOTE: For this problem, we will assume that all variability in our random variables is Gaussian in nature. Consequently, something like “FixedCosts=150000±1000 per month” means that the fixed costs for a given month will be a number randomly selected from a normal distribution with mean 150000 and standard deviation 1000. Also, we will assume that the cost for each unit is constant for a given month (ie, if you sell 1978 units in a given month, each of those units will have the same cost – there will not be 1978 different costs). Finally, we will allow negative values for fixed costs, unit cost, and sales volume, though they are very unlikely (so, no extra adjustments need to be made to the random numbers).
The steps below should guide you to your answer and explore the important aspects of Monte Carlo simulation:
a. Create a loop that on each iteration calculates and saves a value for a monthly NetProfit according to the formula given above. In order to do this, a value for each variable on the righthand side of the formula needs to be set in each iteration of the loop (using random numbers to select a value from your distributions when necessary). This loop should be implemented in a function called matlab_monte_carlo. An input to this function should be the number of monthly net profits to estimate (you may choose to include other input arguments); the output from this function should be a vector of estimates of net profits (one element per iteration of the loop).
• Remember that you can use randn to generate random numbers selected from the standard normal distribution. You can make use of these values to obtain random numbers selected from normal distributions with other means/standard deviations. You
Homework 3
Due by 9am 6/21/16. Submit 5 files.
are also welcome to search for/make use of other Matlab commands (especially ones in
various toolboxes) that may help you in generating the random numbers that you need. b. Plot the histogram of NetProfit values, noting somewhere on the plot how many monthly net
profits this represents (your input to the function). Make sure to that your histogram is presented (number of bins, bin locations, labeling, etc) in a way that provides appropriate, effective, useful communication. Discuss (in a comment) how changing the number of times you are calculating net profits changes the plot.
NOTE: Your code should run pretty quickly for these.
NOTE: Before you start using matlab_monte_carlo and the random numbers that it generates, please initialize the state of the random number generator appropriately (ie, so that it will be in a “random” state).
Problem 2. For this problem you will be using the image file beach.jpg. This should be written as a function with an input argument of a .jpg filename and no output arguments. Name both the function and file beach_plot. Include comments and help lines. Do not include any images in your submission, your script should create them all.
a. Assume the user will have the beach.jpg file in the current directory and will run the function by typing beach_plot(‘beach.jpg’); in the command line.
b. Ask the user to select a point anywhere in the image. Use this point to create 4 quadrants to your image (imagine this in your head, you’re not doing anything with it quite yet).
c. Create a new image where
i. In the upper left quadrant, you plot the original portion of the image without any red
(the red portion is zero)
ii. In the upper right quadrant, you plot the original portion of the image without any
iii. In the lower left quadrant, you plot the original portion of the image without any blue
iv. In the lower right quadrant, you plot the original portion of the image
d. An example is shown below. Hint: if you are getting the message “Integer operands are required for colon operator when used as index” look into the floor command and ask yourself, does my user have to pick a point exactly between two pixels? Note: “Warning: Image is too big to fit on screen” is an ok error to get since it depends on the individual screen resolution.
Homework 3
Due by 9am 6/21/16. Submit 5 files.
Problem 3. For this problem you will be creating a .wav file of twinkle twinkle little star. I have written a function for your use called note_freq which takes an input character and converts it to the corresponding musical frequency. For example, the C on a piano above “middle C” corresponds to a frequency of 523.28 Hz.
You should create a function named twinkle that plays the tune “ccggaag” pause “ffeeddc” by calling the function note_freq. I do not want to see individual lines of code calling each and every note – condense using your programming skills. The function should also write a .wav file with a name specified by the user. The function input arguments should be 1) the sampling rate in Hz at which the song should be played and saved (20000Hz is a good number to play with) and 2) the desired filename which the song will save to. It will be assumed that note_freq is in the current folder. Include help lines and comments. Play the song once at the desired rate in addition to saving it to file.
Note: in case you’re feeling creative, you can add more notes and play pretty much anything http://www.phy.mtu.edu/~suits/notefreqs.html

Homework 3
Due by 9am 6/21/16. Submit 5 files.
Problem 4.
To get started: Create a structural array containing all of the information needed to plot a data set. At a minimum, the structural array should have the following fields
x_data y_data type plot_title x_label y_label x_range y_range
x data (one or more data sets in separate cells) y data (one or more data sets in separate cells) linear, semilogx, and so on
plot title
x axis label
y axis label
x axis range to plot y axis range to plot
You may add additional fields that would enhance your control of the final plot.
The real assignment: After this structural array is created, create a function that accepts a structural array of this format and produces one plot for each structure in the array. The function should apply intelligent defaults if some data fields are missing. For example, if the plot_title field is an empty matrix, then the function should not place a title on the graph or cause an error. Think carefully about the proper defaults before starting to write your function!
To test your function, create a structure array containing the data for three plots of three different types and pass that structure array to your function. The function should correctly plot all three data sets in three different figure windows. The data, labels, titles, ranges, types etc should be different for all three plots.
What to turn in: A script named input_struc.m containing your test structure with the information for the three plots (described above). A function named plot_struc.m that is able to take your structural array and plot all three graphs in different figure windows.
How I will test this: First, I’ll create a variable using your script file and run it through your function. Then, I will use a structure of my own (but following your formatting) that may be missing information from certain fields and try and run it through your function.

June 9, 2016







June 6, 2016
Java | Game|Java Game Agent

For this project you will be implementing an agent to play a simple text-based adventure game. The agent is required to move around a rectangular environment, collecting tools and avoiding (or removing) obstacles along the way. The obstacles and tools within the environment are represented as follows:
Obstacles Tools
T tree a axe
– door k key
~ water o stepping stone
* wall g gold

The agent will be represented by one of the characters ^, v, < or >, depending on which direction it is pointing. The agent is capable of the following instructions:

L turn left
R turn right
F (try to) move forward
C (try to) chop down a tree, using an axe
U (try to) unlock a door, using a key

When it executes an L or R instruction, the agent remains in the same location and only its direction changes. When it executes an F instruction, the agent attempts to move a single step in whichever direction it is pointing. The F instruction will fail (have no effect) if there is a wall, tree or door directly in front of the agent.

April 2, 2016
CS110 quiz4 solution


April 1, 2016
CS110 HW5 solution

CS110: Introduction to Computing
Spring 2015, Tue/Thu, 5:30 PM – 6:45 PM
Instructor: Pejman Ghorbanzade
Assignment 5
Release Date: Apr 19, 2015 at 00:00 AM
Due Date: Apr 30, 2015 at 05:30 PM
Question 1
Write a program FlightTest.java that controls two airplanes, one plane1
a commercial plane from Eagle company and one plane2, a ghter-bomber
from Dragon company. All airplanes y at some altitude and with some
speed. They take o and land. Just as bombers may drop bomb (if they
have any) while they are in sky, commercials can board passengers (as much
as their capacity allows) while grounded.
Assuming all planes made by Eagle have 300 seats, y at 39000 ft and 550
mph and all planes made by Dragon have 2 bomb bays and y at 30000 ft
and 1000 mph, develop classes Aircraft, Bomber, Commercial, Eagle and
Dragon and use them in a program FlightTest.java.

March 12, 2016
c struct and linked list



  • In this homework you are expected to code in C language using Struct and linked list in UNIX environment.
  • Compilation of the necessary files are to be done in a makefile which should resolve all dependencies between headers and C source codes




  1. Create students: …………………………………………………………………………………………………. (25 points)


  • Create a Struct called Student with the following attributes in a file named Student.c

Name (String)

ID (int)

GPA (double)

May 21, 2015
java maze solver

Due Date

Monday, April 20th, at 5:30pm

Important: This is an individual assignment. Please do not collaborate.

No late assignment will be accepted.

Make sure that you write every line of your code. Using code written by someone else will be considered a violation of the academic integrity and will result in a report to the Dean’s office.

Minimal Submitted Files

You are required, but not limited, to turn in the following source files:

Assignment11.java (You do not need to modify this file.)
MazeSolver.java — complete this file.
Position.java (You do not need to modify this file)

Requirements to get full credits in Documentation

The assignment number, your name, StudentID, Lecture number, and a description of each class/file need to be included at the top of each file/class (in this assignment, you might have only one file/class, but in future there will be more than one file.)
A description of each method is also needed.
Some additional comments inside of methods (especially for a “main” method) to explain code that are hard to follow should be written. You can look at Java programs in the text book to see how comments are added to programs.
New Skills to be Applied