This is the solution to Quiz 2: Problems - Programming history, MATLAB variables.
The following figure illustrates the grade distribution for this quiz.
- (A) What is the closest programming language to machine code (i.e., binary code)?
Answer:
Assembly
(B) Does it need interpretation in order to become machine-comprehensible?
Answer:
Yes. An Assembler interprets the program for the machine.
- (A) Name the oldest high-level programming language that is still in active daily usage.
Answer:
Fortran
(B) Approximately how many decades is it old? ($\pm15$ years is accetasble answer. the decade it was created is also an acceptable answer)
Answer:
in 1950s
- (A) Name a second-generation programming language.
Answer:
Assembly
(B) Which language-generation are Fortran, C, C++, MATLAB?
Answer:
third, third, third, fourth
- In what decades C, C++, and MATLAB were created, respectively?
Answer:
1970s, 1980s, 1980s
- Name an ancestor programming language of C.
Answer:
B
- Name a programming language ancestor of C++.
Answer:
C, Simula
- Name a programming language ancestor of MATLAB.
Answer:
Fortran
- Initialized a cell array variable
C
of size $2\times2$, then fill its elements like the following figure.
Answer:
>> C = cell(2,2) >> C{1,1} = [1,3,-7;2,0,6;0,5,1]; >> C{1,2} = 'This is a text string.'; >> C{2,1} = []; >> C{2,2} = [3+4i,-5;-10i,3-4i];
>> C C = [3x3 double] 'This is a text string.' [] [2x2 double] >> C{1,1} ans = 1 3 -7 2 0 6 0 5 1 >> C{2,2} ans = 3.0000 + 4.0000i -5.0000 + 0.0000i 0.0000 -10.0000i 3.0000 - 4.0000i
- Now, if you type
C{2}
on the MATLAB command line, what do you get? Why do get this value?
Answer:
You will get the value for the cell element $(2,1)$. This is happens, because as we discussed in class, MATLAB is column-wise language.
- Does MATLAB follow column-wise data storage, or row-wise? Explain what it means? Why does it follow this storage method? (if you recall, we discussed this in class)
Answer:
MATLAB stores data in a column-major (columnwise) numbering scheme, which is how Fortran stores matrices. MATLAB uses this convention because it was originally written in Fortran. MATLAB internally stores data elements from the first column first, then data elements from the second column second, and so on, through the last column.
- How many bytes is a MATLAB integer of type
int64
? (if you recall, we discussed this in class)
Answer:
8 bytes.
- What would happen if you tried to covert a huge integer number that requires MATLAB
int64
data type to the MATLABint32
data type? (if you recall, we discussed this in class)
Answer:
The huge number is converted to the maximum number that can be represented byint32
data type.>> intmax('int32') ans = 2147483647 >> intmax('int64') ans = 9223372036854775807 >> int32(intmax('int64')) ans = 2147483647
This is a language-specific rule. In other programming languages, the number may be converted to infinity, if it is bigger than the maximum number that can be represented by the requested integer type.