How do I use the equation live editor?

12 views (last 30 days)
I have a very complicated code that I can't make sense of on paper. Is there a good way to convert this to an equation I can actually see and can figure out what's going on in non-code format. Even when I spend the 15 minutes figuring out what the equation represents on paper, I can't be sure it is right due to the complexity (especially with parentheses). This has been a continuous problem so I would like a "teach a man to fish" solution rather than just giving me the equation.
(g/((beta*g*rho)/T)^(1/2) - (g^2*rho*(beta + 1))/(2*T*((beta*g*rho)/T)^(3/2)))/(2*((g*(beta + 1))/((g*rho*beta)/T)^(1/2))^(1/2))
I tried using the help page "Insert Equations into the Live Editor" but the first step is "Go to the Insert tab and click Equation":
https://www.mathworks.com/help/matlab/matlab_prog/insert-equations.html
On my matlab page there is no "insert" tab. I only have tabs for "editor" "publish" and "view." There is an "insert" option in the editor tab, but this is only used to insert fa section, function or fi... Is there a toolbox that I need to add to get the "insert" tab?
As you can probably tell, searching for "insert" tab in google or matlab answers only gives me solutions for inserting a tab...
  1 Comment
Cris LaPierre
Cris LaPierre on 14 Nov 2018
Edited: Cris LaPierre on 14 Nov 2018
What version of MATLAB are you using? You must be on at least r2016a.
There is no need to install any toolboxes to have access.
'Insert Equation" started on the Live Editor ribbon and then moved to a separate "Insert" tab, so it will depend on your version where it is. Just look for a summation symbol in your toolstrip similar to what is in the top of the text edit box here in MATLAB Answers (Σ).
Here is the getting started video from r2016a in case that helps see where it might be.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 14 Nov 2018
Edited: Cris LaPierre on 17 Nov 2018
You can only insert equations into a live script. Follow these steps to convert a *.m to a *.mlx if necessary. Or under '+ New', select 'Live Script'. Note in this image there is not yet an Insert tab. Just Publish and View.
Equations can be entered in LaTeX or built manually, but there is no good way to take an equation written in code and have the equation interpreter display it nicely. However, if what you want is a good way to visualize the equation, live scripts are great at displaying symbolic equations.
Create symbolic variables then enter the equation and run the code.
syms beta g T rho
(g/((beta*g*rho)/T)^(1/2) - (g^2*rho*(beta + 1))/(2*T*((beta*g*rho)/T)^(3/2)))/(2*((g*(beta + 1))/((g*rho*beta)/T)^(1/2))^(1/2))
ans =
To see it in context of the entire MATLAB interface, I'm including a screen shot as well. Note that the 'Editor' tab now says 'Live Editor', and 'Publish' now says 'Insert'. This is in r2018b.
livescriptEqn.png
  2 Comments
Dylan Languth
Dylan Languth on 14 Nov 2018
I see, I didn't realize I had to go into a different script. That works just as well though, thanks for the answer!
Cris LaPierre
Cris LaPierre on 14 Nov 2018
If you haven't seen live scripts before, I'd recommend looking at the getting started video above. They can make code much more readable. Execution can be a little slower if you use the run button, but when called from the command window, live scripts are on par with *.m files.

Sign in to comment.

More Answers (1)

Tasneem Anwar
Tasneem Anwar on 9 Jan 2021
syms theta4
-(r3^2)+(r11^2)+((r4^2)*(cos(theta4))^2)+(2*r11*r4*cos(theta4)+r2^2*(cos(theta2)^2)-2*r2*r11*cos(theta2)-2*r2*r4*cos(theta2)*cos(theta4)+(r9^2)+2*r9*r4*sin(theta4)+(r4^2)*(sin(theta4)^2)+(r2^2)*(sin(theta2))^2-(2*r2*r9*sin(theta2))+(2*r2*r4*sin(theta2)*sin(theta4))

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!