Starting from:

$30

Introduction to Scientific Computing-Homework 1 Solved

Problem 1 : When a fair die is rolled, the number uppermost is equally likely to be any integer from 1 to 6. Thus, if rand is a random number in the range [0, 1), 6 * rand will be in the range [0, 6) and 6 * rand + 1 will be in the range [1, 7), that is, between 1 and 6.9999. Discarding the decimal part of this expression with floor gives an integer in the required range. (a)  Generate a vector d of 20 random integers in the range 1 to 6.

(b)       Count the number of “sixes” thrown by summing the elements of the logical vector d == 6.

 

Problem 2 : Set up a matrix (table) with radians in the first column from 0 to 2π in steps of π/6, degrees in the second column, sines in the third column, and cosines in the fourth column. 

 

Problem 3 : Consider the following system of linear equations

−23x1 −18x2 +2x3 −19x4 −15x5 = 22

                                                               − −x1 16x2 +10x x3 + +4 3x5 =−21

                                                                −15x1 −23x x2 + +3  8x4 +7x5 =−20     

−19x1 +7x2 +2x3 +19x4 −4x5 =−18

−15x1 −11x2 −3x3 −11x4 −15x5 =−17

Solve this system of equations using three syntactically distinct methods in a single script file (m file). The arrays corresponding to the solutions of x should be named xSol1, xSol2, and xSol3 for solution methods 1, 2, and 3, respectively. What are the values of x1 through x5 to three significant figures?

 

Problem 4 : Consider the following structure plan, where M and N represent MATLAB variables: 1. Start

2.    Input M, N

3.    While M not equal to N repeat: While M > N repeat:

Replace value of M by M - N   While M < N repeat:

                        Replace value of N by N - M

4.    Display M

5.    Stop

(a)          Set M = 44 and N = 28, then work through the structure plan, sketching the contents of M and N during execution. Give the output.

(b)          Repeat (a) for M = 14 and N = 24.

 

Problem 5 : Hypocycloids, epicycloids, epitrochoids and hypotrochoids are all fancy names for curves generated when a circle rotates about another circle (a.k.a. roulettes). You can find interesting descriptions and .gifs for all of these roulettes on Wikipedia. You will write a short MATLAB function with the following function declaration:

function spirograph(R,r,d)

You function will generate curves of the following form

ææR+röqö÷

x(q)=(R+r)cosq+dcosçèçè r ÷ø ø

 y(q)=(R+r)sinq- dsinæçèæçèRr+rö÷øq÷öø

You should begin by creating an array called theta that has values between 0 and 10π in steps of no more than 0.001 radians. You can do this using MATLAB’s colon operator or the linspace command. You will then compute values for x and y using array operations, addition, subtraction, the cosine function, etc. This should all be achieved without loops. Once you have the two arrays, x and y, your function should plot the curve using the command plot(x,y). Look at the help pages for the plot command to determine the visualization options this command offers and how you can go about changing the color or style of the plotted line.

Include pretty plots for the following values of R, r, and d in your assignment submission.

 

Plot number 



1
5
1
0.4
2
12
-1
1.5
3
7
-1
1
 

 

Problem 6 : Fibonacci sequences often appear in nature. See the following link for a

description of Fibonacci numbers: http://en.wikipedia.org/wiki/Fibonacci_number The Fibonacci sequence is described by the relationship

F F Fn = n−1 + n−2

where 2≤n<N with N being some integer. The initial values of the Fibonnaci sequence are F0 =0 and F1 =1

The Fibonnaci sequence for N = 6 is:  0, 1, 1, 2, 3, 5, 8.

You are to write a program that returns a vector of the first N Fibonacci numbers with the following function declaration:

function nums = fib(N) 

% fib(N) returns a list of the first N Fibonacci Numbers. % N must be an integer. 

What is the Fibonacci sequence for N = 20?  

 

More products