MATLAB Basics, Desktop Tools, Polynomial Algebra, and Symbolic Calculus Notes
MATLAB Overview and System Architecture
- Definition and Origin:
- MATLAB stands for MATrix LABoratory.
- It is a high-performance, modern programming language environment designed specifically for technical computing.
- It seamlessly integrates computation, data visualization, and a flexible programming environment.
- Structural Features:
- Features sophisticated data structures, built-in editing and debugging software tools, and object-oriented programming support.
- Enables both "programming in the small" (rapid prototyping and execution of throw-away programs) and "programming in the large" (building complete, large-scale, complex application programs).
- The Five Major Components of the MATLAB System:
- Development Environment: A comprehensive set of tools and software facilities designed to assist in using MATLAB functions and managing files.
- Mathematical Function Library: A vast, built-in library of computational algorithms ranging from basic elementary functions (e.g., sum, sine, cosine, complex number arithmetic) to advanced numerical methods (e.g., matrix inversion, matrix eigenvalues, Bessel functions, fast Fourier transforms).
- MATLAB Language: A high-level matrix/array language featuring control flow logic, custom functions, specialized data structures, input/output operations, and object-oriented programming capabilities.
- Graphics Facilities: High-level and low-level tools for vector and matrix visualization, 2D and 3D plotting, image processing, animation, presentation graphics, and graphical output annotation or printing.
- Application Program Interface (API): A functional library allowing C and Fortran programs to interface with MATLAB, enabling dynamic linking, execution of MATLAB as a computational engine, and reading/writing MAT-files.
Development Environment and Graphical User Interface
- Core Desktop Interface Tools:
- Command Window: The primary interface where users enter interactive commands and expressions at the command prompt
>>. A blinking cursor signifies that MATLAB is waiting for mathematical operations or commands. - Command History: Logs all previously executed commands for reference, inspection, re-execution, or script generation.
- Start Button and Launch Pad: Provides convenient shortcut access to tools, installed toolboxes, applications, and documentation.
- Help Browser: A integrated graphical search interface for browsing, searching, and viewing system documentation.
- Current Directory Browser: Allows users to view, manage, and change active file folders and file dependencies.
- Workspace Browser: Displays the active memory workspace containing all variables created during a MATLAB session along with metadata (name, size dimensions, byte memory, and data class type, such as
double array). - Array Editor: A spreadsheet-like interface for viewing and manually editing workspace variable contents. It can be accessed in three distinct ways:
- Double-clicking the targeted variable inside the Workspace Browser.
- Selecting the variable inside the Workspace Browser and clicking the Open button.
- Executing the command syntax
openvar('variable_name')in the Command Window. - Editor/Debugger: An integrated environment used to write, edit, and debug M-files (scripts and function files containing program statements).
- Breakpoints: Execution pause indicators set in script lines to pause execution for variable evaluation.
- Datatips: Hovering the cursor over a variable in debug mode displays a popup showing its current runtime value.
- Text Tools: Provides automated indentation and block commenting/uncommenting options via the Text menu, as well as string search-and-replace features.
- Profiler: A performance diagnostic tool for tracking script execution speed and optimizing computational bottlenecks.
- Command Window: The primary interface where users enter interactive commands and expressions at the command prompt


Session Management and Help Systems
- System Commands for Managing Memory and Session:
clear: Clears and removes all active variables from the workspace memory, freeing up system RAM.who: Displays a concise list of all variable names currently present in active memory.whos: Displays an expanded, detailed inventory of workspace variables, including matrix size dimensions, byte allocation, total memory footprint, and data class types.exist: Checks whether a specified variable, file, or workspace item exists.global: Declares a variable to have global scope across functions and workspace environments.help: Searches for specified help topics and prints summary documentation text directly in the Command Window.lookfor: Searches through help entries and topic header summary lines for a given keyword search term.quit: Terminates and exits the MATLAB program session.

- Interactive Documentation Functions:
helpbrowser: Opens the full Help window browser interface.help function_name: Displays plain-text command documentation forfunction_namedirectly in the Command Window.helpwin function_name: Opens the help document forfunction_namein a separate Help Window.doc function_name: Displays full, detailed reference manual documentation forfunction_nameinside a separate web/doc browser window.

Numerical Formats, Constants, and Operations
- Command Window Numeric Display Formats:
- Display format commands alter only the visual presentation in the output window; they do not impact underlying double-precision numerical storage or computational accuracy.
format short: Standard default setting; displays numbers with four decimal places (e.g.,pidisplays as3.1416).format long: Displays numbers with sixteen decimal places (e.g.,pidisplays as3.14159265358979).format short e: Displays five decimal places accompanied by exponential notation (e.g.,pidisplays as3.1416e+000).format long e: Displays sixteen decimal places accompanied by exponential notation (e.g.,pidisplays as3.14159265358979e+000).format bank: Displays numbers rounded to two decimal places, matching financial/currency standards (e.g.,pidisplays as3.14).format rat: Computes and displays a rational fractional approximation (e.g.,pidisplays as the fraction355/113).format: Resets the output display format to defaultshortfour decimal places.

- Special System Variables and Mathematical Constants:
ans: Stores the default system variable holding the most recent calculated answer.iorj: The fundamental imaginary unit value .Inf: Numerical infinity representation (), resulting from calculations like division by zero.NaN: Not-a-Number; represents an undefined or mathematically unrepresentable numerical result (such as ).pi: Built-in numerical constant representing .

- Scalar Arithmetic Operators and Order of Precedence:
- Addition operator symbol:
+ - Subtraction operator symbol:
- - Multiplication operator symbol:
* - Right Division operator symbol:
/(computes numerator divided by denominator, e.g.,6 / 3evaluates to2corresponding to ) - Left Division operator symbol:
\(computes denominator divided by numerator, e.g.,6 \ 3evaluates to0.5corresponding to ) - Exponentiation operator symbol:
^(e.g.,a^bevaluates to )
- Addition operator symbol:

Operational Precedence Rules:
Expressions are evaluated strictly from left to right across equal precedence tiers.
Order 1 (Highest): Exponentiation (
^).Order 2: Multiplication (
*) and Division (/,\) carrying equal precedence.Order 3 (Lowest): Addition (
+) and Subtraction (-) carrying equal precedence.Parentheses
()override standard operational hierarchy. Computation executes starting from the innermost nested set outwards.Command line spacing is ignored during execution and serves purely to improve human readability.
Built-In Elementary Mathematical Functions:
Trigonometric Functions (input arguments must be expressed in radians):
cos(x): Computes the cosine .sin(x): Computes the sine .tan(x): Computes the tangent .acos(x): Computes the inverse cosine (arc cosine) .asin(x): Computes the inverse sine (arc sine) .atan(x): Computes the inverse tangent (arc tangent) .
Exponential and Logarithmic Functions:
exp(x): Computes the exponential base , returning .log(x): Computes the natural logarithm .log10(x): Computes the common base-10 logarithm .sqrt(x): Computes the square root .
Numerical Rounding and Remainder Functions:
abs(x): Computes absolute numerical value .ceil(x): Rounds argument towards positive infinity ().floor(x): Rounds argument towards negative infinity ().round(x): Rounds argument to the nearest integer value.rem(x, y): Calculates the numerical remainder following division of by y$.\n - `primes(x)`: Returns a vector list containing all prime numbers up to value x$.
Complex Number Analysis Functions:
angle(x): Computes the complex phase angle of complex number x$.\n - `conj(x)`: Computes the complex conjugate of complex number x$.real(x): Extracts the real numerical component of complex input x$.\n - `imag(x)`: Extracts the imaginary numerical component of complex input x$.


- Variables, Execution Controls, and History Navigation:
- Variables store values assigned via expression syntax (e.g.,
a = 2). Variable names are strictly case-sensitive (aandArefer to separate variables). - Terminating a command line with a semicolon
;executes the mathematical command while suppressing visual output echo in the Command Window. - Variable Overwriting: Re-assigning a new value to an existing variable overwrites its memory storage. However, prior outputs calculated previously using the former variable value do not update automatically.
- Line Editing and Command Recall: Keyboard arrow keys (Left , Up , Right , Down ) navigate and recall past command line history.
- Comments Syntax: Any text placed following a percent sign
%on a line is treated as an non-executing comment.
- Variables store values assigned via expression syntax (e.g.,
Polynomial Algebra and Operations
- Coefficient Array Representation:
- Polynomials are represented in array format as row vectors containing coefficients arranged in descending order of power.
- For example, the polynomial function is specified as the array
f = [12, 0, -3, 1, 7]. Note that missing power terms (like ) must explicitly include0as their coefficient place-holder.
- Polynomial Multiplication (
conv):conv(a, b)calculates polynomial multiplication by computing the convolution of coefficient arraysaandb. The two polynomials do not require equal degrees.- Worked Example: Multiplying and :
matlab u = [1 0 1]; v = [2 7]; w = conv(u, v) Output:w = 1x4array containing2 7 2 7, representing the product polynomial 2x^3 + 7x^2 + 2x + 7$.\n\n\n\n- Polynomial Division (`deconv`):\n - `[q, r] = deconv(num, den)` divides a numerator polynomial `num` by a denominator polynomial `den` using deconvolution.\n - Returns the quotient polynomial array `q` and remainder polynomial array `r`.\n - Worked Example: Dividing u = 2x^3 + 7x^2 + 4x + 9v = x^2 + 1:\n ```matlab\n u = [2 7 4 9];\n v = [1 0 1];\n [q, r] = deconv(u, v)\n ```\n Output: Quotient `q = 1x2` array `[2 7]` (2x + 72x + 2).\n\n\n\n- Polynomial Roots and Coefficient Reconstruction (`roots`, `poly`):\n - `roots(a)` computes all roots of the polynomial represented by array `a`, returning them as a column vector.\n - `poly(r)` computes polynomial coefficient values from a vector of roots `r`, returning a row vector ordered by descending powers.\n - `roots` and `poly` operate as inverse functions: `poly(roots(p))` returns original array `p` (up to roundoff tolerance).\n - Worked Example: For polynomial p(x) = x^2 - x - 6:\n ```matlab\n p = [1 -1 -6];\n r = roots(p)\n ```\n Output: Column vector `r` containing `3` and `-2`.\n Reconstructing coefficient vector:\n ```matlab\n p2 = poly(r)\n ```\n Output: Row vector `p2` containing `1 -1 -6`.\n\n\n\n- Partial Fraction Expansion (`residue`):\n - `[r, p, k] = residue(b, a)` solves partial fraction expansions for polynomial ratios \frac{b(s)}{a(s)}, returning residues vector `r`, poles vector `p`, and direct terms vector `k`.\n - Worked Example: Expand ratio F(s) = \frac{b(s)}{a(s)} = \frac{-4s + 8}{s^2 + 6s + 8}\n ```matlab\n b = [-4 8];\n a = [1 6 8];\n [r, p, k] = residue(b, a)\n ```\n Output: Residues `r = [-12; 8]`, Poles `p = [-4; -2]`, Direct Term `k = []`.\n This yields the expanded expression: \frac{-4s + 8}{s^2 + 6s + 8} = \frac{-12}{s + 4} + \frac{8}{s + 2}.\n\n\n\n- Polynomial Evaluation (`polyval`):\n - `polyval(a, x)` evaluates a polynomial with coefficient array `a` across input values specified in `x` (where `x` can be a scalar, vector, or matrix).\n - Worked Example: Evaluate p(x) = 3x^2 + 2x + 1x = 5, 7, 9:\n ```matlab\n p = [3 2 1];\n polyval(p, [5 7 9])\n ```\n Output: `ans = [86 162 262]`.\n - Verification: 3(5)^2 + 2(5) + 1 = 75 + 10 + 1 = 86\n - Verification: 3(7)^2 + 2(7) + 1 = 147 + 14 + 1 = 162\n - Verification: 3(9)^2 + 2(9) + 1 = 243 + 18 + 1 = 262\n\n# Calculus: Differentiation, Limits, and Integration\n\n- Symbolic Variable Declaration:\n - Performing symbolic calculus operations requires prior declaration of symbolic variables using the syntax `syms variable_name` (e.g., `syms x`, `syms y`, `syms z`).\n- Symbolic Differentiation (`diff`):\n - Command Syntax Formats:\n - `diff(f)` or `diff(f, x)`: Computes the first derivative \frac{df}{dx}.\n - `diff(f, a)`: Computes the derivative with respect to specified symbol a\frac{df}{da}).\n - `diff(f, b, 2)`: Computes the second-order derivative with respect to symbol b\frac{d^2f}{db^2}).\n - `diff(f, x, n)`: Computes the nx.\n - Worked Derivatives for y = \sin^2(x): \n - First derivative y' = \frac{d}{dx}(\sin^2(x)):\n ```matlab\n syms x\n diff((sin(x))^2)\n ```\n Output: `2*cos(x)*sin(x)`\n - Second derivative y'' = \frac{d^2}{dx^2}(\sin^2(x)):\n ```matlab\n diff((sin(x)^2), 2)\n ```\n Output: `2*cos(x)^2 - 2*sin(x)^2`\n - Third derivative y''' = \frac{d^3}{dx^3}(\sin^2(x)):\n ```matlab\n diff((sin(x)^2), 3)\n ```\n Output: `-8*cos(x)*sin(x)`\n - Fourth derivative y^{(4)} = \frac{d^4}{dx^4}(\sin^2(x)):\n ```matlab\n diff((sin(x)^2), 4)\n ```\n Output: `8*sin(x)^2 - 8*cos(x)^2` \n\n\n\n- Limits of Functions (`limit`):\n - Command Syntax Formats:\n - `limit(f)`: Evaluates limit as variable approaches zero \lim_{x \to 0} f(x).\n - `limit(f, x, a)` or `limit(f, a)`: Evaluates limit as variable approaches a\lim_{x \to a} f(x)).\n - `limit(f, x, a, 'right')`: Evaluates right-hand directional limit \lim_{x \to a^+} f(x).\n - `limit(f, x, a, 'left')`: Evaluates left-hand directional limit \lim_{x \to a^-} f(x).\n - Worked Limit Calculations:\n - Evaluation 1: \lim_{x \to 5} \frac{2x - 10}{x^3 - 125}\n `limit((2*x-10)/(x^3-125), x, 5)` \rightarrow Output: `2/75`\n - Evaluation 2: \lim_{x \to 3} \frac{x - 3}{x^2 - 9}\n `limit((x-3)/(x^2-9), x, 3)` \rightarrow Output: `1/6`\n - Evaluation 3: \lim_{x \to 0^-} \frac{1}{x}\n `limit((1/x), x, 0, 'left')` \rightarrow Output: `-Inf`\n - Evaluation 4: \lim_{x \to 1^+} \frac{x^2 - 1}{\sin^2(x - 1)}\n `limit((x^2-1)/(sin(x-1))^2, x, 1, 'right')` \rightarrow Output: `Inf` \n\n\n\n- Symbolic Integration (`int`, `pretty`):\n - Command Syntax Formats:\n - `int(f)` or `int(f, x)`: Evaluates indefinite integral \int f(x)\,dx\n - `int(f, y)`: Evaluates indefinite integral with respect to symbol y\int f(x, y)\,dy)\n - `int(f, a, b)` or `int(f, x, a, b)`: Evaluates definite integral over interval [a, b]\int_a^b f(x)\,dx)\n - `int(f, y, a, b)`: Evaluates definite integral with respect to symbol y[a, b]\int_a^b f(x, y)\,dy)\n - `pretty(expression)`: Typesets symbolic expressions into clean ASCII mathematical formatting.\n - Worked Integration Calculations:\n - Evaluation 1: Indefinite integral \int \sqrt{x^5}\,dx\n ```matlab\n int(sqrt(x^5))\n ```\n Output: `(2*x*(x^5)^(1/2))/7` \n Pretty Print: `pretty(int(sqrt(x^5)))` displays \frac{2 x \sqrt{x^5}}{7}.\n - Evaluation 2: Definite integral \int_0^1 \sqrt{z}\ln(z)\,dz\n ```matlab\n syms z\n int(sqrt(z)*log(z), 0, 1)\n ```\n Output: `-4/9`\n - Evaluation 3: Definite integral \int_1^2 \frac{1}{y}\,dy\n ```matlab\n syms y\n int(1/y, 1, 2)\n ```\n Output: `log(2)`\n - Evaluation 4: Definite Gaussian integral \int_0^\infty e^{-x^2}\,dx\n ```matlab\n int(exp(-x^2), 0, inf)\n ```\n Output: `pi^(1/2)/2` (\frac{\sqrt{\pi}}{2}) \n Pretty Print: `pretty(int(exp(-x^2),0,inf))` displays `sqrt(pi)/2`.\n\n\n\n# Practice Exercises and Computational Problems\n\n- Direct Arithmetic Expression Evaluations:\n - Problem 1a: Evaluate 2{-4 - [6 + 3 + (7 - (1 + 8)) + 12] - 3} + 5\n - Problem 1b: Evaluate -5{-[-2 + 6 - 8(4 - (7 - 4) - 2) + 2] - 1}\n - Problem 1c: Evaluate \frac{12 - 3(2)}{3(-2) - 3(-2)}\n - Problem 1d: Evaluate \frac{2 - 5(8 - (-4))}{4 - (-2)} \div \frac{5 - 8}{-2 - 5}\n - Problem 1e: Given x = \frac{\pi}{2}y = \sin(x)y = 1z = \arcsin(y).\n - Problem 1f: Evaluate \cos\left(\frac{\pi}{2}\right).\n- Variable Computations given x = 3y = 4:\n - Problem 2a: Evaluate 3\pi x^2\n - Problem 2b: Evaluate \cos(0.3) - 1\n - Problem 2c: Evaluate e^{-\frac{1}{5}x} - 1\n - Problem 2d: Evaluate \left(\frac{1}{4x} - \frac{8}{3y}\right)^{-1}\n - Problem 2e: Evaluate \frac{3x - 6}{4(y - 5)}\n- Scalar Formulations for Test Values a = 1.12b = 2.34c = 0.72d = 0.81f = 19.83:\n - Statement 3a: Write MATLAB command for x = 1 + \frac{a + b + c^2}{f}\n - Statement 3b: Write MATLAB command for s = \frac{a - b - c}{d}\n - Statement 3c: Write MATLAB command for r = \frac{1}{\frac{1}{a} + \frac{1}{b} + \frac{1}{c} + \frac{1}{d}}\n - Statement 3d: Write MATLAB command for y = \frac{1}{2} a b \sqrt{c^2 + f^2}\n- Complex Variable Computations for x = 5 + 8iy = -6 + 7i:\n - Complex Problem 4a: Evaluate u = x + y\n - Complex Problem 4b: Evaluate v = x y\n - Complex Problem 4c: Evaluate w = \frac{x}{y}\n - Complex Problem 4d: Evaluate z = e^x\n - Complex Problem 4e: Evaluate r = \sqrt{y}\n - Complex Problem 4f: Evaluate s = x y^2$$