How to properly use Symbolic Toolbox to implement superscripts and subscripts on imaginary numbers and theta

Greetings community,
I'll begin by saying that I am not an engineer or math expert. This question arose during my independent research to understand kinematics, more specifically complex number addition and vector loops.
Part of this expirement is that I want to learn more about properly using the Symbolic Toolbox to be able to write expressions as seen in this image snippet. However, I am failing to use the superscripts and subscripts properly. Consider the following code snippet:
syms V1 theta_1 i
V1_expr = V1 * exp(theta_1 * 1i)
As the more educated person can see, it will not produce the desired outcome as shown in the image above. It will subscript theta with 1. Instead I have tried to subscript the imaginary number but MatLab gets upset when I do that. What I get as a result that works right now is:
Would anyone be willing to assist me?
Cheers,

1 Comment

Be careful. If you use
syms V1 theta_1 i
V1_expr = V1 * exp(theta_1 * i)
then i is treated as just another symbol, instead of as the special constant sqrt(-1)

Sign in to comment.

 Accepted Answer

The "syms" function in MATLAB's Symbolic Toolbox allows you to create symbolic scalar variables and functions, and matrix variables and functions.
The code below generates desired expression:
syms V1 theta1 i
V1_expr = V1 * exp(i * theta1);
disp(V1_expr);
Please refer to the following MathWorks documentation for more information on "syms": https://www.mathworks.com/help/symbolic/syms.html

5 Comments

This is the same code that @Clayton Allen already posted, but Clayton got a different result.
Probably Clayton is using regular .m files. Fancy formatting is not available for regular .m files.
Fancy formatting is available for LiveScript (and MATLAB Online, and MATLAB Answers)
I can confirm @Walter Roberson this was created using an MLX file type. That's how I was able to grab the screen snip of the output posted above.
Cheers,
The error in my script as you pointed out was using:
V1_expr = V1 * exp(1i * theta_1)
Instead of:
V1_expr = V1 * exp(i * theta_1)
Thanks for your assistance.
Cheers,
In LiveScript, both expressions are the same.
Unfortunately due to a bug in MATLAB Answers, I cannot show you the outputs. (They are there... just not showing up.)
clear i %MATLAB Answers glitch, i initialized as [] sometimes
syms V1 theta_1
V1_expr = V1 * exp(theta_1 * 1i);
disp(V1_expr)
V2_expr = V1 * exp(theta_1 * i);
disp(V2_expr)
Oh... That is a good catch! I went in and tested the values out and found what you pointed out.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2024b

Tags

Community Treasure Hunt

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

Start Hunting!