in this video we will be talking about
how to include and generate latex
equations in matlab
you can insert mathematical equations
into your matlab script to describe a
mathematical process or method used in
your code
let's start by opening out a matlab live
script
a live script closely resembles the
final document that you will share with
others
live scripts combine matlab code with
natural reading elements such as
formatted text images and latex
equations so you can tell a story with
your work
to insert an equation in your live
script
go to the insert tab
click equation
the first option allows you to build an
equation interactively to insert a latex
equation select the second option
or on your keyboard you can use shift
ctrl and l to bring up this window
now enter a latex expression in the
dialog box that appears
for example you can enter the maclaurin
series for sine of x the preview pane
shows a preview of the equation as it
would appear in the live script
to include a description of the latex
equation when exporting the live script
to html add text to the alt text field
for example you can enter the text
maclaurin series for sine of x
now press ok to insert the equation into
your live script
if you are not familiar with latex
expressions you can easily find the
latex form of symbolic expressions in
matlab
the latex function returns the latex
form of the symbolic expression
for example let's find the latex form of
these symbolic expressions let's start
by creating the symbolic variables x and
phi this command creates the symbolic
variables x and phi in the matlab
workspace
we will then use the latex function to
find the latex form of these expressions
now let's go ahead and run these lines
of code
similarly we can find the latex form of
symbolic arrays and perform computation
using several symbolic matrix variables
and then find their latex forms
we can use the latex function to format
title access labels and ticks of plots
let's plot the 3d surface y sine of x
minus x cos of y for x and y from minus
pi to 2 pi
here we store the axis object in a by
using gca
gca is used to refer to the current axis
display the axis box by using a dot box
and set the tick label interpreter to
latex
let's now go ahead and run this section
we will now create the x-axis sticks by
spanning the x-axis limits at intervals
of pi by 2.
then we get the symbolic tick values in
s by converting the access limits to
precise multiples of pi by 2 using round
we can display the text by setting the x
tick property of a to s create the latex
labels for the x-axis by using the
function add-a-fun to apply latex to s
and these labels that we created can be
displayed by assigning them to the
x-stick label property of a
let's go ahead and repeat this for the
y-axis
finally let's set the x-axis and y-axis
labels and the title using the latex
interpreter
once you are done working on your live
script
you can send live scripts to other
matlab users or export them in a variety
of file formats like export to pdf
export to word and so on
let's select export to latex
you can save your file and you now have
a latex file which you can share
if you want to learn more about how you
can insert and generate latex equations
in matlab and the examples that we used
in this video feel free to go through
the links in the description