Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Way to convert code into a mathematically readable format ...

Subject: Way to convert code into a mathematically readable format ...

From: SSOI SS

Date: 23 Aug, 2012 09:18:05

Message: 1 of 5

Hi, a simple question but perhaps no easy answers:

Does anyone know whether there is an algorithm or way to convert code (e.g. java, c etc) into a mathematically readable text format. One example is:

Input:

A = ( ( ( ( ( (X ) * Y ) / Z) * Q) * P) / R );

Output:

        X * Y * Q * P
A = -----------------------
             Z * R


Thanks for any advice.

Subject: Way to convert code into a mathematically readable format ...

From: Justin Ashmall

Date: 23 Aug, 2012 13:15:07

Message: 2 of 5

"SSOI SS" wrote in message <k14sgd$fcn$1@newscl01ah.mathworks.com>...
> Does anyone know whether there is an algorithm or way to convert code (e.g. java, c etc) into a mathematically readable text format. One example is:
> Input:
> A = ( ( ( ( ( (X ) * Y ) / Z) * Q) * P) / R );
> Output:
> X * Y * Q * P
> A = -----------------------
> Z * R

I don't know about the Matlab symbolic toolkit, but this is the kind of thing you can do in Mathematica and/or WolframAlpha if it's just a one-off:

http://www.wolframalpha.com/input/?i=+%28+%28+%28+%28+%28+%28X+%29+*+Y+%29+%2F+Z%29+*+Q%29+*+P%29+%2F+R+%29%3B

Subject: Way to convert code into a mathematically readable format ...

From: Steven_Lord

Date: 23 Aug, 2012 13:17:29

Message: 3 of 5



"SSOI SS" <wonderful.song@googlemail.com> wrote in message
news:k14sgd$fcn$1@newscl01ah.mathworks.com...
> Hi, a simple question but perhaps no easy answers:
> Does anyone know whether there is an algorithm or way to convert code
> (e.g. java, c etc) into a mathematically readable text format. One example
> is:
> Input:
>
> A = ( ( ( ( ( (X ) * Y ) / Z) * Q) * P) / R );
>
> Output:
>
> X * Y * Q * P
> A = -----------------------
> Z * R

In MATLAB? Take a look at the PUBLISH function or, if your expression uses
symbolic variables created using SYM or SYMS from Symbolic Math Toolbox take
a look at the PRETTY function.

In general? LaTeX, MathJax:

http://blogs.mathworks.com/cleve/2012/06/03/cleves-corner-blogs-edition/

or some of the other options here:

http://en.wikipedia.org/wiki/Category:Mathematical_markup_languages

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Way to convert code into a mathematically readable format ...

From: SSOI SS

Date: 23 Aug, 2012 14:16:06

Message: 4 of 5

Hi Steven,
Actually I was searching something more simple who can generate the equations in text format. Maybe the example was too easy, because in C codes there are lots of things which don't correspond to Matlab coding rules. I don't know whether the methods you told can handle them well.

Anyway, thanks

"Steven_Lord" <slord@mathworks.com> wrote in message <k15ah8$3ea$1@newscl01ah.mathworks.com>...
>
>
> "SSOI SS" <wonderful.song@googlemail.com> wrote in message
> news:k14sgd$fcn$1@newscl01ah.mathworks.com...
> > Hi, a simple question but perhaps no easy answers:
> > Does anyone know whether there is an algorithm or way to convert code
> > (e.g. java, c etc) into a mathematically readable text format. One example
> > is:
> > Input:
> >
> > A = ( ( ( ( ( (X ) * Y ) / Z) * Q) * P) / R );
> >
> > Output:
> >
> > X * Y * Q * P
> > A = -----------------------
> > Z * R
>
> In MATLAB? Take a look at the PUBLISH function or, if your expression uses
> symbolic variables created using SYM or SYMS from Symbolic Math Toolbox take
> a look at the PRETTY function.
>
> In general? LaTeX, MathJax:
>
> http://blogs.mathworks.com/cleve/2012/06/03/cleves-corner-blogs-edition/
>
> or some of the other options here:
>
> http://en.wikipedia.org/wiki/Category:Mathematical_markup_languages
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Way to convert code into a mathematically readable format ...

From: SSOI SS

Date: 23 Aug, 2012 14:17:07

Message: 5 of 5

Hi Justin,

Thank you for the link. It works for my simple example, but if i put complicated c codes into the box, then it doesn't work. Maybe the strings from codes are too long for the processor

"Justin Ashmall" wrote in message <k15acr$2q7$1@newscl01ah.mathworks.com>...
> "SSOI SS" wrote in message <k14sgd$fcn$1@newscl01ah.mathworks.com>...
> > Does anyone know whether there is an algorithm or way to convert code (e.g. java, c etc) into a mathematically readable text format. One example is:
> > Input:
> > A = ( ( ( ( ( (X ) * Y ) / Z) * Q) * P) / R );
> > Output:
> > X * Y * Q * P
> > A = -----------------------
> > Z * R
>
> I don't know about the Matlab symbolic toolkit, but this is the kind of thing you can do in Mathematica and/or WolframAlpha if it's just a one-off:
>
> http://www.wolframalpha.com/input/?i=+%28+%28+%28+%28+%28+%28X+%29+*+Y+%29+%2F+Z%29+*+Q%29+*+P%29+%2F+R+%29%3B

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us