MATLAB Art by Me

What is MATLAB? Why do we need a math programming language?

MATLAB was created by a professor in New Mexico in the 1970s to address the demands of his students to compute easy matrix operations using software.

Short for “MATrix LABoratory”, this was a collection of linear algebra libraries that students could call to solve difficult problems.

Since then MATLAB has not looked back and has continued to develop new libararies and tools to help mathamaticians and engineers solve difficult problems.

During my undergrad at University of California, San Diego, I used MATLAB quite a bit to solve common mechanical engineering problems in statics, dynamics, and fluids. Expecially, whenever linear algebra was involved, the default was to use MATLAB. It’s just super easy and efficient at solving large matrix equations, which allowed me to have the time to focus on the actual engineering problem and not the computation problem.

MATLAB Airplane Simulation

MATLAB libraries Examples

Don’t wanna hand convert coordinates to polar coordinates? Just call this function instead!

%--------------------------------------------------------------------------
%
% Calculate polar components
%
% Last modified:   2018/01/27   Meysam Mahooti
%
%--------------------------------------------------------------------------
function [m_phi, m_theta, m_r] = CalcPolarAngles(m_Vec)
% Length of projection in x-y-plane:
rhoSqr = m_Vec(1) * m_Vec(1) + m_Vec(2) * m_Vec(2); 
% Norm of vector
m_r = sqrt(rhoSqr + m_Vec(3) * m_Vec(3));
% Azimuth of vector
if ( (m_Vec(1)==0) && (m_Vec(2)==0) )
    m_phi = 0;
else
    m_phi = atan2(m_Vec(2), m_Vec(1));
end
if ( m_phi < 0 )
    m_phi = m_phi + 2*pi;
end
% Altitude of vector
rho = sqrt( rhoSqr );
if ( (m_Vec(3)==0) && (rho==0) )
    m_theta = 0;
else
    m_theta = atan2(m_Vec(3), rho);
end

When in doubt, ode45 it out. Solve differential equations with the call of a function

% Define the ODE function
function dydt = myODE(t, y)
    dydt = -2 * y;
end

% Set up the problem
tspan = [0 5];  % Time interval from 0 to 5
y0 = 1;         % Initial condition y(0) = 1

% Solve the ODE
[t, y] = ode45(@myODE, tspan, y0);

% Plot the results
plot(t, y);
xlabel('Time');
ylabel('y(t)');
title('Solution of dy/dt = -2y');

Simulink takes the powerful MATLAB libararies that it offers and allows you to create dynamic models with inputs and outputs.

I first got exposure to Simulink making controls diagrams that would simulate balancing a ball using a PID controller.

Simulink PID Controller

MATLAB Tool Box

When I was working as a system engineer, I quite frequently used the MATLAB Radar Toolbox.

I found it very useful to not only help me compute radar equations like the Signal-to-Noise Ratiol, but it was very effective at creating visualizations so I could effectively communicate my results with both my manager and various stakeholders.

MATLAB Radar Toolbox

Excellent Documentation

MATLAB documentation is world renowned. If you have a problem, MATLAB will have the answer.

MATLAB Documentation

Convert to Low Level C

Python users (myself included) usually criticize MATLAB for being expensive, not as open-source as python, and catered specifically only for large engineering companies.

While all these critiques are true, and it is usually better to individually code small projects with python, MATLAB has the advantage of converting your MATLAB code to be run in C++ to get better performance than python.

MATLAB C++