Solutions to MATLAB & LaTeX Exam Questions
Group A: MATLAB
Q1(a) How to declare matrix in MATLAB?
In MATLAB, matrices are declared using square brackets [].
Example: A = [1 2 3; 4 5 6; 7 8 9];
Q1(b) Which command enables a title for the x-axis?
Command: xlabel('text').
Example: xlabel('Time (s)');
Q1(c) Plot sin(t) and cos(t) in same graph
t = 0:0.1:2*pi;
plot(t, sin(t), 'r', t, cos(t), 'b');
legend('sin(t)', 'cos(t)');
Q2(a) Create magic matrices M, N and add them
M = magic(4);
N = magic(4);
X = M + N;
Q2(b) Specify Line and Marker appearance
plot(x, y, 'r--o'); % red dashed line with circle markers
Group B: LaTeX
Q1(a) Colortext package
Use \usepackage{color} or \usepackage{xcolor}.
Example: {\color{red} Red Text}
Q1(b) Difference between array and tabular
array is for math mode, tabular is for text mode tables.
Q1(c) dvipsnames
Used under package: \usepackage[dvipsnames]{xcolor}
Q1(d) Why enumerate?
It is used to create numbered lists.
Example: \begin{enumerate} \item First \item Second \end{enumerate}
Q1(e) Why scalebox?
It is used to resize text or figures.
Example: \scalebox{2}{Text}
Q1(f) Write equation g(x) = dx^2 + cx + b
\[ g(x) = dx^2 + cx + b \]
Q1(g) Difference between hfill and vfill
\hfill adds horizontal space, \vfill adds vertical space.
Q3(a) Piecewise function
\[ S(x) = \begin{cases} -1, & x<0 \\ 0, & x=0 \\ 1, & x>0 \end{cases} \]
Q3(b) Series notation
\[ a+b+\cdots+z \]
Q3(c) Relation
\[ u+v \approx w \approx z \]
Q4(a) Integral and Summation
\[ \int_0^{\infty} f(x) dx \approx \sum_{i=1}^n w_i e^{x_i} f(x_i) \]
Q4(b) Table Example
\begin{tabular}{|c|c|c|c|} \hline Year & Winners & Runners-up & Host \\ \hline 2018
& France & Croatia & Russia \\ 2022 & Argentina & France & Qatar \\ \hline
\end{tabular}
Extra Question: Script vs Function File
Script File: A file containing sequence of MATLAB commands executed together.
Function File: A file that accepts inputs and returns outputs. Defined using the keyword function.