Download CSCI 101 - Assignment 3 – Due 15 August 11:59 pm Assignment

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CSCI 101 - Assignment 3 – Due 15 August 11:59 pm
Assignment-3 MATLAB Ch 1, 2, 4, 5 and CS Ch 2
Objectives: Practice problem solving with MATLAB and learn more about machine language.
1.
Submission instructions
1. Submit your pdf report and problem solutions under http://www.acadox.com/class/19089
in the relevant task as one zip file. The report should contain a pdf file with all your full
answers plus any script files you developed for your answers.
2. No late submission is allowed.
3. Book a time slot with your TA to discuss your answers and bring a printed copy of them.
4. Do not even think of plagiarizing. Any unoriginal work submitted will be penalized.
1. In special relativity, the Lorentz factor* is a number that describes the effect of speed on
various physical properties when the speed is significant relative to the speed of light.
Mathematically, the Lorentz factor is given as:𝛾 =
1
2
√1βˆ’π‘£ 2
(0.5 mark)
𝑐
8
Use 3 βˆ— 10 m/s for the speed of light, c. Create variables for c and the speed v and from them
a variable Lorentz for the Lorentz factor. * https://en.wikipedia.org/wiki/Lorentz_factor
2. Create a vector x which consists of 20 equally spaced points in the range from -𝛱 to 𝛱.
Create a y vector which is sin(x). Then plot the relation x-y.
(0.5 mark)
3. Most major airports have separate lots for long-term and short-term parking. The cost to park
depends on the lot you select, and how long you stay. Consider this rate structure from the
Salt Lake International Airport during the summer of 2008.
(1 mark)
I. Long-Term (Economy) Parking:
ο‚· The first hour is $1.00, and each additional hour or fraction thereof is $1.00
ο‚· Daily maximum (if you spent a full day parking) $6.00
ο‚· Weekly maximum (if you spent a full week parking) $42.00
II. Short-Term Parking:
ο‚· The first 30 minutes are free and each additional 20 minutes or fraction thereof is $1.00
ο‚· Daily maximum $25.00
Write a program that uses nested if-else statements and asks the user the following:
β€’ Which lot are you using? (Use menu)
β€’ How many weeks, hours, days, and minutes did you park? (Use input)
Your program should then calculate the parking bill.
Write another program using switch/case statements instead.
4. A Fibonacci sequence is composed of elements created by adding the two previous elements.
The simplest n Fibonacci sequence starts with 1, 1 and proceeds as follows
(0.5 mark)
1, 1, 2, 3, 5, 8, 13, …
However, a Fibonacci sequence can be created with any two starting numbers. Fibonacci
sequences appear regularly in nature.
Prompt the user to enter the first two numbers in a Fibonacci sequence and the total number
of elements requested for the sequence. Find the sequence and store it in an array.
Plot your results on a polar graph. Use the element number for the angle and the value of the
Element in the sequence for the radius.
5. Solve problem 6.10 in: MATLAB for Engineers, 4th ed., by Holly More.
(0.75 marks)
6. Solve problem 6.11 in: MATLAB for Engineers, 4th ed., by Holly More.
(0.75 marks)
See these links for more on anonymous functions:
http://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html
http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/
http://blogs.mathworks.com/loren/2013/01/10/introduction-to-functional-programming-withanonymous-functions-part-1/
2.
Bonus
7. Go to https://www.mathworks.com/matlabcentral/cody
Type one of these: physics or chemistry or math and sort results from the most liked to the
least liked. Solve 10 non-basic problems and show your TA your work. Challenge yourself.
Solve hard problems.
(1 mark)
8. Go to the machine language simulator at http://schweigi.github.io/assembler-simulator/
Read, understand and run the default program and get familiar with the machine language
being simulated and the main categories of instructions available in it.
(1 mark)
Modify the program or write new one that
takes the two sides of a rectangle (assume
they are stored at memory locations 220 and
222) and prints a message: β€œRectangle area is
xxx”.
1
Note that printing is tricky as you need to convert
the binary number representing the area to a
sequence of numerical characters. E.g., if the area
is 00111011, you need to print 5 and 9 (ASCII 53
and 57). If you print 00111011 directly, it will
print the equivalent ASCII character which is β€œ;”.
2
Note: The machine has 4 general purpose
registers and 256 memory locations.
3
Note: The machine uses memory mapping. So, if
you want to write to the consol (screen), you write
to memory location 232 in the memory and it
appears on the screen.
; Simple example
; Writes Hello World to the output
JMP start
msg: DB "Hello World!" ; Variable
DB 0
; String terminator
start:
MOV C, msg
; Point to var
MOV D, 232 ; Point to output
MOV B, 0
CALL printmsg
HLT
; Stop execution
printmsg:
; print(C:*from, D:*to)
MOV A, [C] ; Get char from var
MOV [D], A ; Write to output
INC C
INC D
JNZ printmsg
; jump if not
RET