How to enter math formula in Matlab as they appear in math
8 views (last 30 days)
Show older comments
When I enter a long complicated math formula in Matlab, it's hard for me to read the formula. I would like to enter fractions as they appear in math and not using a/b form. I would like to use the square root symbol instead of sqrt. If the function argument and the syntax to group terms were different it would be great, currently both are () in Matlab. Are there editors for Matlab which support these features? I would like to be able to run the code directly from that editor too.
0 Comments
Answers (4)
Roger Stafford
on 15 Mar 2015
I heartily agree, Yashar. I, also, would like to do these things with formulas and equations, and much more. For a long time I have dreamed of the possibility of creating expressions such as one might draw on a chalkboard, and moreover being able to manipulate with them in such a way that only mathematically allowable changes were permitted. In the Symbolic Toolbox we are allowed to do such things as "simplify", "collect", "expand", and the like, but these offer only a very limited control over the form of expressions. It would be great to directly move terms around, invoke the distributive law, use trigonometric or other identities, all under the watchful eye of a highly intelligent successor to Matlab. Besides extensive software development, I suspect this would also require something far more sophisticated in physical equipment than existing computer keyboards, mouse, and monitor screens.
0 Comments
John D'Errico
on 15 Mar 2015
Edited: John D'Errico
on 15 Mar 2015
I would like to enter expressions in MATLAB merely by thinking about them. Why should we need to type things, or even bother with a mouse? This would be a great boon to individuals with carpal tunnel problems, and to those who are stricken with paralysis in many forms. Just think of how more efficient someone like Steven Hawking could become if he had better interfaces to tools like this over the years?
Even better, why should we need to be forced to think about code? Code should write itself. Computers should be smart enough that they no longer need us. Hmm, is that the plot for a new movie or book? I might also point out that Hawking himself did utter fears about that eventuality.
What Yasher seems to misunderstand is the huge reason as to why MATLAB works as well as it does. It works on different operating systems. MATLAB code that is 25 or even 30 years old now, STILL runs. I know, because I have useful, running code that is more than 25 years old. The point is, a text based tool allows your code to work, to be upwardly and backwardly compatible for MANY years after you write it. This one fact is INCREDIBLY valuable. Seriously, it is. I fully expect the many tools I have posted on the File Exchange to be of use for many years to come. As well, the same m-file will work on Linux systems, Windoze, Mac, etc.
If you insist on a nice pretty interface as you seem to want, then perhaps you are looking at the wrong software. You might consider something like MathCad. Ok, I'm not even sure that tool still exists. Gosh, I wonder if there is a reason why MathCad seems to have fallen off the face of the earth, and MATLAB has grown by leaps and bounds over the years? I hope you see my point - that MATLAB has had the longevity it has had for many reasons, but a big one is the simple text based interface that allows it to work across systems with no problems.
3 Comments
John D'Errico
on 15 Mar 2015
Thanks. I'm still not sure what led the spam filters to think it was spam.
Jan
on 15 Mar 2015
It sounds nice and useful, what you describe. But this is definitely not Matlab anymore. I do not think that there is an editor with these feature and which run smoothly in Matlab.
Do you work with the symbolic toolbox already?
2 Comments
Jan
on 15 Mar 2015
I've worked with large equations for the simulation fo multi-body-systems with several joints and constraints. For the first experiments with a double pendulum or a hopping robot I've calculated the equations on paper and it was not trivial to convert this to Matlab code without typos.
But for larger systems with hundreds of variables this method is too prone to errors. Therefore the determination of the coordinates was performed with Maple. And this software for symbolic operations could create FORTRAN, C and MATLAB code as output. :-) Today the Symbolic Toolbox of Matlab would be a direct way to create the formulas neatly.
So the best method to avoid typos is to avoid the need to copy large formulas from paper to code. But if I have to copy e.g. a formula from a text book, I split the equation into smaller parts, such that the length of a code line does not exceed one or two text lines. In this step constant parts of the expressions are identified and moved before loops. The remaining parts are simplified furtherly until it gets clear, which can be vectorized to increase the processing speed. This means that complicated formulas are not simply copied to Matlab code, but restructured to allow for a more efficient computation. Therefore this is not only a boring job and prone to typos, but the translation of the problem from math to numerics.
Aaron Becker
on 8 Apr 2015
I sympathize, and do enjoy other languages with beautifully type-set formulae. Still, if we are constrained to monospaced text, you can improve code readability by splitting long expressions into functions and choosing good function names. The file exchange: "Matlab Programming Style Guidelines" has some great tips.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!