Forgive me if this may be already asked. I am kind of new to all this. I wondered if there is a simple facility to have Matlab or R import or convert from LaTeX documents? This would be no different than how you can create a MuPAD script document and convert into Matlab M code. This would be through the Matlab Math Symbol toolbox.
Thanks
No, converting general LaTeX equations into some sort of procedural programming language is most decidedly not possible.
LaTeX is a system for creating documents with structured text formatting and typesetting. It is not much different than writing individual letters and symbols onto a piece of paper yourself; there are no intrinsic semantics as to which symbols mean what. It doesn't know (or care) if the expression x = y is an assignment or a test for equality. Or if \cdot is a dot product or simple multiplication. All that really matters in the end is that the equations are readable and look good to a human eye. To convert this soup of symbols into a procedural programming language is quite impossible.
MuPAD, however, is a computer algebra system. You tell it what is a function and what are variables. It has this knowledge. As such, it is able to identify inputs and outputs and some sort of directional flow. It has a grammar to its equations: you must, for example, use := to denote assignment. When converting to an m-file, MuPAD uses this additional information to determine which variables are scalar or vector, what is an assignment and what is a boolean test, what is input and what is output, etc.
This difference is obvious in usage of MuPAD vs LaTeX: one can rearrange and simplify your equations for you, the other cannot.
Related
Is there an efficient implementation of the set data structure in R?
In C++ I would use an std::set (which is implemented using red-black trees), in Python a set (which is implemented using hash tables), but I am not sure what I should use in R.
I have found this link, which describes some set operations, like union() and intersection(), that you can perform on vectors. So, I guess that since vectors are involved, the complexities would not be logarithmic, as you could have using the data structures mentioned above.
Fun fact, note how in this case the name of the language does not help, searching "r set" one finds many results concerning $\mathbb{R}$, and not the programming language :D
I'm currently working on a Calculator app and I want output to be in both a simplified expression and decimal answer form. An example would be sqrt 2 * sqrt 3 = sqrt 6 which can also be outputted as 2.44948... What is the best approach to this and is there any well-established algorithms to do this?
Yes. What you likely want is a computer algebra system, which understands formulas as artifacts to be manipulated by explicit mathematics rules.
Mathematica and Macsyma are applications which do this. However, these are quite sophisticated systems and it is not easy to see how they "work".
What you need to do is:
Represent formulas as abstract syntax trees
Parse text formulas (your example equations) into such trees
Encode a set of tree-manipulation rules that represent algebra operations
Apply these rules to your algebra trees
Prettyprint the algebra trees back as text when done
Rules are best written in the surface syntax of algebra. (Mathematica doesn't do this; it represents formulas as trees using a kind of prefix S-expressions, and rules as the same kind of trees with special variable nodes).
One of the issues is deciding how many "algebra" rules you are wiling to encode. Mathematics is a lot more than pure 9th grade algebra, and people using such systems tend to want to extend what is there by adding more knowledge (the point of Mathematica and Macsyma: they are infinitely extendable).
Here's a very simple version of this. You can see all the "gears" and how things are described, in terms of parse trees and rewrite rules.
http://www.semdesigns.com/Products/DMS/SimpleDMSDomainExample.html
Basically I have created two MATLAB functions which involve some basic signal processing and I need to describe how these functions work in a written report. It specifically requires me to describe the algorithms using mathematical notation.
Maths really isn't my strong point at all, in fact I'm quite surprised I've even been able to develop the functions in the first place. I'm quite worried about the situation at the moment, it's the last section of writing I need to complete but it is crucially important.
What I want to know is whether I'm going to have to grab a book and teach myself mathematical notation in a very short space of time or is there possibly an easier/quicker way to learn? (Yes I know reading a book should be simple enough, but maths + short time frame = major headache + stress)
I've searched through some threads on here already but I really don't know where to start!
Although your question is rather vague, and I have no idea what sorts of algorithms you have coded that you are trying to describe in equation form, here are a few pointers that may help:
Check the MATLAB documentation: If you are using built-in MATLAB functions, they will sometimes give an equation in the documentation that describes what they are doing internally. Some examples are the functions CONV, CORRCOEF, and FFT. If the function is rather complicated, it may not have an equation but instead have links to some papers describing the algorithm, which may themselves have equations for the algorithm. An example is the function HILBERT (which you can also find equations for on Wikipedia).
Find some lists of common mathematical symbols: Some standard symbols used to represent common mathematical operations can be found here.
Look at some sample pseudocode to see how it's done: For algorithms you yourself have coded up, you'll have to write them out in equation or pseudocode form. A paper that I've used often in my work is Templates for the Solution of Linear Systems, and it has some examples of pseudocode that may be helpful to you. I would suggest first looking at the list of symbols used in that paper (on page iv) to see some typical notations used to represent various mathematical operations. You can then look at some of the examples of pseudocode throughout the rest of the document, such as in the box on page 8.
I suggest that you learn a little bit of LaTeX and investigate Matlab's publish feature. You only need to learn enough LaTeX to write mathematical expressions. Then you have to write Matlab comments in your source file in LaTeX, but only for the bits you want to look like high-quality maths. Finally, open the Matlab editor on your .m file, and select File | Publish.
See Very Quick Intro to LaTeX and check your Matlab documentation for publish.
In addition to the answers already here, I would strongly advise using words in addition to forumlae in your report to describe the maths that you are presenting.
If I were marking a student's report and they explained the concepts of what they were doing correctly, but had poor or incorrect mathematical notation to back it up: this would lose them some marks, but would hopefully not impede my understanding of the hard work they've put in.
If they had poor/wrong maths, with no explanation of what they meant to say, this could jeapordise my understanding of their entire project and cost them a passing grade.
The reason you haven't found any useful threads is because most of the time, people are trying to turn maths into algorithms, not vice versa!
Starting from an arbitrary algorithm, sometimes pseudo-code, along with suitable comments, is the clearest (and possibly only) representation.
does anybody familiar with a way that I could implement a matrix with values from a field (not the real or complex number, but lets say Z mod p). so I could perform all the operation of matlab on the matrix (with the values of the chosen field)
Ariel
I suspect that you will want to use Matlab's object-oriented capabilities so that you can define both the fundamental representation of the elements of your field, and the basic operations on them. There's a reasonably good, if elementary, example of implementing polynomials using Matlab's OO features in the product documentation. That might be a good place for you to start.
I would like to use Python to generate my own algebra to pre-calculus worksheets to print and use. The purpose is to teach kids how to practice algebra. What is the best way generate the expressions?
Update:
I am planning to use Latex to generate nicely formatted equations.
The question I have is how to come up with a large number of the equations. One way of doing this is to define the list for each topics but this is tedious. I want to automate using some kind generator (e.g. Context Free Grammar)
If you want to generate nice looking typeset equations, you should probably output LaTeX code, which can then be compiled into pdf, dvi, postscript, or what have you. There are a few python libraries for this, but it's just text so generating it shouldn't be much of a problem once you know how it works. Alternatively, you can embed python code into a LaTeX document using something like this. In any case I haven't tried any of the python libraries for this so I can't really recommend any of them.
My approach to this problem would be to write a Python script to generate a LaTeX document which could then be compiled into a PDF document to be printed.
I assume that you want Python so that the sheets are different.
One way to do this would be to generalize the structure of an equation. The simplest ones are properly those that are of the form:
a*x+b*x+c=d*x+e*x+f
(any of the values can be 0, and they need not be distinct). Then I would suggest you simply constructed a method to return the latex code to typeset such an equation, which puts in random values for a, b, c, d, e and f.
You can then call that method as many times a you want different equations.