- home
- PDF letter size
- PDF legal size

General report

How to solve Basic Engineering and Mathematics Problems

using Mathematica, Matlab and Maple

November 30, 2019 Compiled on November 30, 2019 at 2:42pm

This is a collection of how to examples showing the use of Mathematica and Matlab to solve basic engineering and mathematics problems. Few examples are also in Maple, Ada, and Fortran.

This was started as a cheat sheet few years ago, and I continue to update it all the time.

Few of the Matlab examples require the use of toolboxs such as signal processing toolbox and the control systems toolbox (these come free as part of the student version). Most examples require only the basic system installation.

1 Control systems, Linear systems, transfer functions, state space
related problems

1.1 Creating tf and state space and diﬀerent Conversion of forms

1.2 Obtain the step response of an LTI from its transfer function

1.3 plot the impulse and step responses of a system from its transfer function

1.4 Obtain the response of a transfer function for an arbitrary input

1.5 Obtain the poles and zeros of a transfer function

1.6 Generate Bode plot of a transfer function

1.7 How to check that state space system \(x'=Ax+Bu\) is controllable?

1.8 Obtain partial-fraction expansion

1.9 Obtain Laplace transform for a piecewise functions

1.10 Obtain Inverse Laplace transform of a transfer function

1.11 Display the response to a unit step of an under, critically, and over damped system

1.12 View steady state error of 2nd order LTI system with changing undamped natural frequency

1.13 Show the use of the inverse Z transform

1.14 Find the Z transform of sequence x(n)

1.15 Sample a continuous time system

1.16 Find closed loop transfer function from the open loop transfer function for a unity feedback

1.17 Compute the Jordan canonical/normal form of a matrix A

1.18 Solve the continuous-time algebraic Riccati equation

1.19 Solve the discrete-time algebraic Riccati equation

1.20 Display impulse response of H(z) and the impulse response of its continuous time approximation H(s)

1.21 Find the system type given an open loop transfer function

1.22 Find the eigenvalues and eigenvectors of a matrix

1.23 Find the characteristic polynomial of a matrix

1.24 Verify the Cayley-Hamilton theorem that every matrix is zero of its characteristic polynomial

1.25 How to check for stability of system represented as a transfer function and state space

1.26 Check continuous system stability in the Lyapunov sense

1.27 Given a closed loop block diagram, generate the closed loop Z transform and check its stability

1.28 Determine the state response of a system to only initial conditions in state space

1.29 Determine the response of a system to only initial conditions in state space

1.30 Determine the response of a system to step input with nonzero initial conditions

1.31 Draw the root locus from the open loop transfer function

1.32 Find \(e^{A t}\) where \(A\) is a matrix

1.33 Draw root locus for a discrete system

1.34 Plot the response of the inverted pendulum problem using state space

1.35 How to build and connect a closed loop control systems and show the response?

1.36 Compare the eﬀect on the step response of a standard second order system as \(\zeta \) changes

1.37 Plot the dynamic response factor \(R_{d}\) of a system as a function of \(r=\frac{\omega }{\omega _{n}}\) for diﬀerent damping ratios

1.38 How to ﬁnd closed loop step response to a plant with a PID controller?

1.39 How to make Nyquist plot?

2 Linear algebra, Linear solvers, common operations on vectors and matrices

2.1 Multiply matrix with a vector

2.2 Insert a number at speciﬁc position in a vector or list

2.3 Insert a row into a matrix

2.4 Insert a column into a matrix

2.5 Build matrix from other matrices and vectors

2.6 Generate a random 2D matrix from uniform (0 to 1) and from normal distributions

2.7 Generate an n by m zero matrix

2.8 Rotate a matrix by 90 degrees

2.9 Generate a diagonal matrix with given values on the diagonal

2.10 Sum elements in a matrix along the diagonal

2.11 Find the product of elements in a matrix along the diagonal

2.12 Check if a Matrix is diagonal

2.13 Find all positions of elements in a Matrix that are larger than some value

2.14 Replicate a matrix

2.15 Find the location of the maximum value in a matrix

2.16 Swap 2 columns in a matrix

2.17 Join 2 matrices side-by-side and on top of each others

2.18 Copy the lower triangle to the upper triangle of a matrix to make symmetric matrix

2.19 extract values from matrix given their index

2.20 Convert \(N\) by \(M\) matrix to a row of length \(N M\)

2.21 ﬁnd rows in a matrix based on values in diﬀerent columns

2.22 Select entries in one column based on a condition in another column

2.23 Locate rows in a matrix with column being a string

2.24 Remove set of rows and columns from a matrix at once

2.25 Convert list of separated numerical numbers to strings

2.26 Obtain elements that are common to two vectors

2.27 Sort each column (on its own) in a matrix

2.28 Sort each row (on its own) in a matrix

2.29 Sort a matrix row-wise using ﬁrst column as key

2.30 Sort a matrix row-wise using non-ﬁrst column as key

2.31 Replace the ﬁrst nonzero element in each row in a matrix by some value

2.32 Perform outer product and outer sum between two vector

2.33 Find the rank and the bases of the Null space for a matrix A

2.34 Find the singular value decomposition (SVD) of a matrix

2.35 Solve \(Ax=b\)

2.36 Find all nonzero elements in a matrix

2.37 evaluate f(x) on a vector of values

2.38 generates equally spaced N points between \(x_1\) and \(x_2\)

2.39 evaluate and plot a \(f(x,y)\) on 2D grid of coordinates

2.40 Find determinant of matrix

2.41 Generate sparse matrix with \(n\) by \(n\) matrix repeated on its diagonal

2.42 Generate sparse matrix for the tridiagonal representation of second diﬀerence operator in 1D

2.43 Generate sparse matrix for the Laplacian diﬀerential operator \(\nabla ^{2}u\) for 2D grid

2.44 Generate sparse matrix for the Laplacian diﬀerential operator \(\nabla ^{2}u\) for 3D grid

2.45 Generate the adjugate matrix for square matrix

2.46 Multiply each column by values taken from a row

2.47 extract submatrix from a larger matrix by removing row/column

2.48 delete one row from a matrix

2.49 delete one column from a matrix

2.50 generate random matrix so that each row adds to 1

2.51 generate random matrix so that each column adds to 1

2.52 sum all rows in a matrix

2.53 sum all columns in a matrix

2.54 ﬁnd in which columns values that are not zero

2.55 How to remove values from one vector that exist in another vector

2.56 How to ﬁnd mean of equal sized segments of a vector

2.57 ﬁnd ﬁrst value in column larger than some value and cut matrix from there

2.58 make copies of each value into matrix into a larger matrix

2.59 repeat each column of matrix number of times

2.60 How to apply a function to each value in a matrix?

2.61 How to sum all numbers in a list (vector)?

2.62 How to ﬁnd maximum of each row of a matrix?

2.63 How to ﬁnd maximum of each column of a matrix?

2.64 How to add the mean of each column of a matrix from each column?

2.65 How to add the mean of each row of a matrix from each row?

2.66 Find the diﬀerent norms of a vector

2.67 Check if a matrix is Hermite

2.68 Obtain the LU decomposition of a matrix

2.69 Linear convolution of 2 sequences

2.70 Circular convolution of two sequences

2.71 Linear convolution of 2 sequences with origin at arbitrary position

2.72 Visualize a 2D matrix

2.73 Find the cross correlation between two sequences

2.74 Find orthonormal vectors that span the range of matrix A

2.75 Solve A x= b and display the solution

2.76 Determine if a set of linear equations A x= b, has a solution and what type of solution

2.77 Given a set of linear equations automatically generate the matrix \(A\) and vector \(b\) and solve \(A x=b\)

2.78 Convert a matrix to row echelon form and to reduced row echelon form

2.79 Convert 2D matrix to show the location and values

2.80 How to ﬁnd equation of line which is the intersection of 2 planes in 3D?

3 signal processing, Image processing, graphics, random numbers

3.1 Generate and plot one pulse signal of diﬀerent width and amplitude

3.2 Generate and plot train of pulses of diﬀerent width and amplitude

3.3 Find the discrete Fourier transform of a real sequence of numbers

3.4 Generate uniform distributed random numbers

3.5 Determine and plot the Fourier Transform for continuous time function

3.6 Use FFT to display the power spectrum of the content of an audio wav ﬁle

3.7 Plot the power spectral density of a signal

3.8 Display spectrum of 2D image

3.9 Obtain Fourier Series coeﬃcients for a periodic function

3.10 Obtain the statistical maximum likelihood estimates (MLE) of probability distributions

3.11 Make a histogram of data sampled from some probability distribution

3.12 apply a ﬁlter on 1D numerical data (a vector)

3.13 apply an averaging Laplacian ﬁlter on 2D numerical data (a matrix)

3.14 How to ﬁnd cummulative sum

3.15 How to ﬁnd the moving average of a 1D sequence?

3.16 How to select N random values from a set of numbers?

3.17 How to sample a sin signal and plot it?

3.18 How ﬁnd the impulse response of a diﬀerence equation?

4 Diﬀerential, PDE solving, integration, numerical and analytical solving of equations

4.1 Generate direction ﬁeld plot of a ﬁrst order diﬀerential equation

4.2 Solve the 2-D Laplace PDE for a rectangular plate with Dirichlet boundary conditions

4.3 Solve homogeneous 1st order ODE, constant coeﬃcients and initial conditions

4.4 Solve homogeneous 2nd order ODE with constant coeﬃcients

4.5 Solve non-homogeneous 2nd order ODE, constant coeﬃcients

4.6 Solve homogeneous 2nd order ODE, constant coeﬃcients (BVP)

4.7 Solve the 1-D heat partial diﬀerential equation (PDE)

4.8 Show the eﬀect of boundary/initial conditions on 1-D heat PDE

4.9 Find particular and homogenous solution to undetermined system of equations

4.10 Plot the constant energy levels for a nonlinear pendulum

4.11 Solve numerically the ODE \(u^{''''}+u=f\) using point collocation method

4.12 How to numerically solve a set of non-linear equations?

4.13 Solve 2nd order ODE (Van Der Pol) and generate phase plot

4.14 How to numerically solve Poisson PDE on 2D using Jacobi iteration method?

4.15 How to solve BVP second order ODE using ﬁnite elements with linear shape functions and using weak form formulation?

4.16 How to solve Poisson PDE in 2D using ﬁnite elements methods using rectangular element?

4.17 How to solve Poisson PDE in 2D using ﬁnite elements methods using triangle element?

4.18 How to solve wave equation using leapfrog method?

4.19 Numerically integrate \(f(x)\) on the real line

4.20 Numerically integrate \(f(x,y)\) in 2D

4.21 How to solve set of diﬀerential equations in vector form

4.22 How to implement Runge-Kutta to solve diﬀerential equations?

4.23 How to diﬀerentiate treating a combined expression as single variable?

4.24 How to solve Poisson PDE in 2D with Neumann boundary conditions using Finite Elements

5 plotting how to, ellipse, 3D

5.1 Generate a plot using x and y data

5.2 Plot the surface described by 2D function

5.3 Find the point of intersection of 3 surfaces

5.4 How to draw an ellipse?

5.5 How to plot a function on 2D using coordinates of grid locations?

5.6 How to make table of \(x,y\) values and plot them

5.7 How to make contour plot of \(f(x,y)\) ?

1.1 Creating tf and state space and diﬀerent Conversion of forms

1.2 Obtain the step response of an LTI from its transfer function

1.3 plot the impulse and step responses of a system from its transfer function

1.4 Obtain the response of a transfer function for an arbitrary input

1.5 Obtain the poles and zeros of a transfer function

1.6 Generate Bode plot of a transfer function

1.7 How to check that state space system \(x'=Ax+Bu\) is controllable?

1.8 Obtain partial-fraction expansion

1.9 Obtain Laplace transform for a piecewise functions

1.10 Obtain Inverse Laplace transform of a transfer function

1.11 Display the response to a unit step of an under, critically, and over damped system

1.12 View steady state error of 2nd order LTI system with changing undamped natural frequency

1.13 Show the use of the inverse Z transform

1.14 Find the Z transform of sequence x(n)

1.15 Sample a continuous time system

1.16 Find closed loop transfer function from the open loop transfer function for a unity feedback

1.17 Compute the Jordan canonical/normal form of a matrix A

1.18 Solve the continuous-time algebraic Riccati equation

1.19 Solve the discrete-time algebraic Riccati equation

1.20 Display impulse response of H(z) and the impulse response of its continuous time approximation H(s)

1.21 Find the system type given an open loop transfer function

1.22 Find the eigenvalues and eigenvectors of a matrix

1.23 Find the characteristic polynomial of a matrix

1.24 Verify the Cayley-Hamilton theorem that every matrix is zero of its characteristic polynomial

1.25 How to check for stability of system represented as a transfer function and state space

1.26 Check continuous system stability in the Lyapunov sense

1.27 Given a closed loop block diagram, generate the closed loop Z transform and check its stability

1.28 Determine the state response of a system to only initial conditions in state space

1.29 Determine the response of a system to only initial conditions in state space

1.30 Determine the response of a system to step input with nonzero initial conditions

1.31 Draw the root locus from the open loop transfer function

1.32 Find \(e^{A t}\) where \(A\) is a matrix

1.33 Draw root locus for a discrete system

1.34 Plot the response of the inverted pendulum problem using state space

1.35 How to build and connect a closed loop control systems and show the response?

1.36 Compare the eﬀect on the step response of a standard second order system as \(\zeta \) changes

1.37 Plot the dynamic response factor \(R_{d}\) of a system as a function of \(r=\frac{\omega }{\omega _{n}}\) for diﬀerent damping ratios

1.38 How to ﬁnd closed loop step response to a plant with a PID controller?

1.39 How to make Nyquist plot?

2 Linear algebra, Linear solvers, common operations on vectors and matrices

2.1 Multiply matrix with a vector

2.2 Insert a number at speciﬁc position in a vector or list

2.3 Insert a row into a matrix

2.4 Insert a column into a matrix

2.5 Build matrix from other matrices and vectors

2.6 Generate a random 2D matrix from uniform (0 to 1) and from normal distributions

2.7 Generate an n by m zero matrix

2.8 Rotate a matrix by 90 degrees

2.9 Generate a diagonal matrix with given values on the diagonal

2.10 Sum elements in a matrix along the diagonal

2.11 Find the product of elements in a matrix along the diagonal

2.12 Check if a Matrix is diagonal

2.13 Find all positions of elements in a Matrix that are larger than some value

2.14 Replicate a matrix

2.15 Find the location of the maximum value in a matrix

2.16 Swap 2 columns in a matrix

2.17 Join 2 matrices side-by-side and on top of each others

2.18 Copy the lower triangle to the upper triangle of a matrix to make symmetric matrix

2.19 extract values from matrix given their index

2.20 Convert \(N\) by \(M\) matrix to a row of length \(N M\)

2.21 ﬁnd rows in a matrix based on values in diﬀerent columns

2.22 Select entries in one column based on a condition in another column

2.23 Locate rows in a matrix with column being a string

2.24 Remove set of rows and columns from a matrix at once

2.25 Convert list of separated numerical numbers to strings

2.26 Obtain elements that are common to two vectors

2.27 Sort each column (on its own) in a matrix

2.28 Sort each row (on its own) in a matrix

2.29 Sort a matrix row-wise using ﬁrst column as key

2.30 Sort a matrix row-wise using non-ﬁrst column as key

2.31 Replace the ﬁrst nonzero element in each row in a matrix by some value

2.32 Perform outer product and outer sum between two vector

2.33 Find the rank and the bases of the Null space for a matrix A

2.34 Find the singular value decomposition (SVD) of a matrix

2.35 Solve \(Ax=b\)

2.36 Find all nonzero elements in a matrix

2.37 evaluate f(x) on a vector of values

2.38 generates equally spaced N points between \(x_1\) and \(x_2\)

2.39 evaluate and plot a \(f(x,y)\) on 2D grid of coordinates

2.40 Find determinant of matrix

2.41 Generate sparse matrix with \(n\) by \(n\) matrix repeated on its diagonal

2.42 Generate sparse matrix for the tridiagonal representation of second diﬀerence operator in 1D

2.43 Generate sparse matrix for the Laplacian diﬀerential operator \(\nabla ^{2}u\) for 2D grid

2.44 Generate sparse matrix for the Laplacian diﬀerential operator \(\nabla ^{2}u\) for 3D grid

2.45 Generate the adjugate matrix for square matrix

2.46 Multiply each column by values taken from a row

2.47 extract submatrix from a larger matrix by removing row/column

2.48 delete one row from a matrix

2.49 delete one column from a matrix

2.50 generate random matrix so that each row adds to 1

2.51 generate random matrix so that each column adds to 1

2.52 sum all rows in a matrix

2.53 sum all columns in a matrix

2.54 ﬁnd in which columns values that are not zero

2.55 How to remove values from one vector that exist in another vector

2.56 How to ﬁnd mean of equal sized segments of a vector

2.57 ﬁnd ﬁrst value in column larger than some value and cut matrix from there

2.58 make copies of each value into matrix into a larger matrix

2.59 repeat each column of matrix number of times

2.60 How to apply a function to each value in a matrix?

2.61 How to sum all numbers in a list (vector)?

2.62 How to ﬁnd maximum of each row of a matrix?

2.63 How to ﬁnd maximum of each column of a matrix?

2.64 How to add the mean of each column of a matrix from each column?

2.65 How to add the mean of each row of a matrix from each row?

2.66 Find the diﬀerent norms of a vector

2.67 Check if a matrix is Hermite

2.68 Obtain the LU decomposition of a matrix

2.69 Linear convolution of 2 sequences

2.70 Circular convolution of two sequences

2.71 Linear convolution of 2 sequences with origin at arbitrary position

2.72 Visualize a 2D matrix

2.73 Find the cross correlation between two sequences

2.74 Find orthonormal vectors that span the range of matrix A

2.75 Solve A x= b and display the solution

2.76 Determine if a set of linear equations A x= b, has a solution and what type of solution

2.77 Given a set of linear equations automatically generate the matrix \(A\) and vector \(b\) and solve \(A x=b\)

2.78 Convert a matrix to row echelon form and to reduced row echelon form

2.79 Convert 2D matrix to show the location and values

2.80 How to ﬁnd equation of line which is the intersection of 2 planes in 3D?

3 signal processing, Image processing, graphics, random numbers

3.1 Generate and plot one pulse signal of diﬀerent width and amplitude

3.2 Generate and plot train of pulses of diﬀerent width and amplitude

3.3 Find the discrete Fourier transform of a real sequence of numbers

3.4 Generate uniform distributed random numbers

3.5 Determine and plot the Fourier Transform for continuous time function

3.6 Use FFT to display the power spectrum of the content of an audio wav ﬁle

3.7 Plot the power spectral density of a signal

3.8 Display spectrum of 2D image

3.9 Obtain Fourier Series coeﬃcients for a periodic function

3.10 Obtain the statistical maximum likelihood estimates (MLE) of probability distributions

3.11 Make a histogram of data sampled from some probability distribution

3.12 apply a ﬁlter on 1D numerical data (a vector)

3.13 apply an averaging Laplacian ﬁlter on 2D numerical data (a matrix)

3.14 How to ﬁnd cummulative sum

3.15 How to ﬁnd the moving average of a 1D sequence?

3.16 How to select N random values from a set of numbers?

3.17 How to sample a sin signal and plot it?

3.18 How ﬁnd the impulse response of a diﬀerence equation?

4 Diﬀerential, PDE solving, integration, numerical and analytical solving of equations

4.1 Generate direction ﬁeld plot of a ﬁrst order diﬀerential equation

4.2 Solve the 2-D Laplace PDE for a rectangular plate with Dirichlet boundary conditions

4.3 Solve homogeneous 1st order ODE, constant coeﬃcients and initial conditions

4.4 Solve homogeneous 2nd order ODE with constant coeﬃcients

4.5 Solve non-homogeneous 2nd order ODE, constant coeﬃcients

4.6 Solve homogeneous 2nd order ODE, constant coeﬃcients (BVP)

4.7 Solve the 1-D heat partial diﬀerential equation (PDE)

4.8 Show the eﬀect of boundary/initial conditions on 1-D heat PDE

4.9 Find particular and homogenous solution to undetermined system of equations

4.10 Plot the constant energy levels for a nonlinear pendulum

4.11 Solve numerically the ODE \(u^{''''}+u=f\) using point collocation method

4.12 How to numerically solve a set of non-linear equations?

4.13 Solve 2nd order ODE (Van Der Pol) and generate phase plot

4.14 How to numerically solve Poisson PDE on 2D using Jacobi iteration method?

4.15 How to solve BVP second order ODE using ﬁnite elements with linear shape functions and using weak form formulation?

4.16 How to solve Poisson PDE in 2D using ﬁnite elements methods using rectangular element?

4.17 How to solve Poisson PDE in 2D using ﬁnite elements methods using triangle element?

4.18 How to solve wave equation using leapfrog method?

4.19 Numerically integrate \(f(x)\) on the real line

4.20 Numerically integrate \(f(x,y)\) in 2D

4.21 How to solve set of diﬀerential equations in vector form

4.22 How to implement Runge-Kutta to solve diﬀerential equations?

4.23 How to diﬀerentiate treating a combined expression as single variable?

4.24 How to solve Poisson PDE in 2D with Neumann boundary conditions using Finite Elements

5 plotting how to, ellipse, 3D

5.1 Generate a plot using x and y data

5.2 Plot the surface described by 2D function

5.3 Find the point of intersection of 3 surfaces

5.4 How to draw an ellipse?

5.5 How to plot a function on 2D using coordinates of grid locations?

5.6 How to make table of \(x,y\) values and plot them

5.7 How to make contour plot of \(f(x,y)\) ?