a) Write a program to compute and print the time and height of the rocket from t = 0 to the time that it hits the ground, in increments of 2 secs. If the rocket has not hit the ground within 100 secs, stop the program. …show more content…
b) Modify the program such that instead of a table, the program prints the time at which the rocket begins falling back to the ground and time at which the rocket impacts.
2. Given a string of characters, we can permute the individual characters to make new strings. If we can impose an ordering on the characters (say alphabetic sequence),then the strings themselves can be ordered and any given permutation can be given a unique number designating its position in that ordering. For example the string `acab' gives rise to the following 12 distinct permutations:
Thus the string `acab' can be characterized in this sequence as 5.
Write a MATLAB program that will read in a string and determine its position in the ordered sequence of permutations of its constituent characters.
Input and Output
Input will consist of a series of lines, each line containing one string. Each string will consist of up to 30 lower case letters, not necessarily distinct.
Output will consist of a series of lines, one for each line of the input. Each line will consist of the position of the string in its
sequence.
Sample input bacaa abc cba Sample output
15
1
6
3 The Hamming distance between two strings of bits (binary integers) is the number of corresponding bit positions that differ. This can be found by using XOR on corresponding bits or equivalently, by adding corresponding bits (base 2) without a carry. For example, in the two bit strings that follow:
A 0 1 0 0 1 0 1 0 0 0
B 1 1 0 1 0 1 0 1 0 0
A XOR B = 1 0 0 1 1 1 1 1 0 0
The Hamming distance (H) between these 10-bit strings is 6, the number of 1's in the XOR string.
Input
N, the length of the bit strings and H, the Hamming distance.
Output
A list of all possible bit strings of length N that are Hamming distance H from the bit string containing all 0's (origin). That is, all bit strings of length N with exactly H 1's.
The program should work for 1<=N<=10 and 1<=H<=10.
Sample
For N=4 and H=2 the output should contain all of the following bit strings (order is unimportant):
0011
0101
0110
1001
1010
1100
C(4, 2) is 6.