How can I draw equations I found on WolframAlpha in MatLAB?

4 views (last 30 days)
Wolfram says that this particular drawing is a parametric. I dont know if that matters?
figure;
hold on;
X = insert long eq here
Y = insert long eq here
plot(X, Y, '-k.');
xlim([-inf, inf])
ylim([-inf, inf])
hold off

Accepted Answer

Adam Danz
Adam Danz on 21 Aug 2020
Edited: Adam Danz on 22 Aug 2020
You must convert the mathematical notation to a syntax recognized by Matlab.
For example, this segment,
becomes any of the following
% 't' is defined in that link as,
t = linspace(0,92*pi,5000); % 5000 is arbitrarily chosen
% Minimalist version
-1/38 * sin(17/11 - 37*t) - 1/30 * sin(31/21 - 35*t)
% Showing use of .* notation (not required here due to matrix dimensions)
-1/38 * sin(17/11 - 37.*t) - 1/30 * sin(31/21 - 35.*t)
% Showing use of parentheses to perceptually group the terms but not
% required due to order of operations
((-1/38) * sin((17/11) - (37.*t))) - ((1/30) * sin((31/21) - (35.*t)))
The key points are
  1. n(sin(x)) must become n*sin(x) or n.*sin(x) depending on the array sizes. You want element-wise operations.
  2. Undersand the order of operations, or use parentheses to group your terms.
  3. Frequently run sections of the equation as you convert each set of terms so you can catch errors early on. The output should be equal in size to the variable t.
  4. For square roots, use sqrt().
  5. As indicated in the WolframAlpha link you shared, theta(x) is the Heaviside step function.
  6. Also indicated in the link, sgn is the sign function.
Update
Due to the negative associations this image may have with current social issues (which I just learned about), I'll refrain from continuing with this thread. I hope the answer helps to learn about converting mathematical notation to Matlab syntax but please be socially minded with the meme.
  4 Comments
Adam Danz
Adam Danz on 22 Aug 2020
That's point #1 in my list. See the link regarding element-wise operations.
Also, I doubt the error message is coming from the section of code you shared.
To troubleshoot, test sections of the equations. For example, I would test the following sections in order from top to bottom. You can highligh these sections and press F9 to see their result (provided all variables are defined).
-1/38 * sin(17/11 - 37*t) - 1/30 * sin(31/21 - 35*t)
------------ ------------
------------------------ ------------------------
----------------------------------------------------
Rachele Tran
Rachele Tran on 24 Aug 2020
Hey!!
Thank you for all your help so far - I still haven't quite gotten it as I'm getting a new error:
Error using sign
Not enough input arguments.
I'm currently in assessment at uni so I'll come back with hopefully Pepe once I figure out what I've done wrong once my workload chills down a bit
I've included the converted matlab plain text thingo for the equations thus far in case you're interested.
Thank you for joining me on my Pepe journey so far!!

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!