Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: √ ∞ ≠ ≤ ≥ ≈ ⇒ ∈ Δ θ ∴ ∑ ∫ π -

Login

Username

Password

Not registered yet?

#1 2005-07-28 19:27:52

Nitrofu
Guest

math notation to code notation

how can i write as code notation (like on programming languages like ansi-basic, C, pascal, etc.) all the math notations we can get from OpenOffice's Math editor?      these can be functions or algoritms

#2 2005-07-28 20:54:43

MathsIsFun
Administrator

Offline

Re: math notation to code notation

I don't use OpenOffice (though it sounds good!), so could you give some examples?


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

#3 2005-08-14 05:38:22

nitrofurano
Novice

Offline

Re: math notation to code notation

an example: standard deviation formula converted to algorithm

the formula is:
D=sqrt{sum from{i=1}to{N}(x_{i}-bar x)^{2}over{N-1}}

the algorithm in sdlBasic (http://sdlbasic.sf.net) is

Code:

'- standard deviation
setdisplay(512,256,32,1):paper(0xFFFFFF):ink(0x000000):pen(0x000000):cls
   n=50
   dim x[n]
while 0=0
prints("Standard Deviation"):prints("")
prints("OpenOffice formula format:")
prints("D=sqrt{sum from{i=1}to{N}(x_{i}-bar x)^{2}over{N-1}}"):prints("")
prints("getting random values..."):prints("")
for i=1 to n
   x[i]=rnd(1000)
 next
close #1
prints("running the formula..."):prints("")
   av_x=0
for i=1 to n
   av_x=av_x+x[i]
 next
   av_x=av_x/n
   sum=0
for i=1 to n
   sum=sum+(x[i]-av_x)^2
 next
   stp3=sum/(n-1)
   d=sqr(stp3)
prints("standard deviation: "+str$(d)):prints("")
waitkey
cls
wend

my main interest is being able to convert formulas like from here: http://www.google.com/search?q=ieee+papers+pdf&sourceid=mozilla-search&start=0&start=0 to algorithm

#4 2005-08-25 14:26:39

ryos
Power Member

Offline

Re: math notation to code notation

Wow. It's been a really long time since I did any C programming, and I don't remember what Math functions are available. So, I'll give a couple simple examples in Java, which has similar syntax.

The Quadratic Formula:

public Point quadform (a, b, c)  {
       float plus, minus;

       plus = (b^2 + Math.sqrt (2*b - 4*a*c)) / (2*a);
       minus = (b^2 - Math.sqrt (2*b - 4*a*c)) / (2*a);

       return new Point (plus, minus);
}

n!:

public double factorial (n)  {
       double answer = 2;

       if (n > 1)  { answer = factorial (n-1); }
       
       return answer * (n-1);
}


This may sound really stupidly obvious, but writing algorithms of math functions is just programming. Get a book and practice. If you're having a problem with a specific function, post a specific question and we'll be happy to answer.

Last edited by ryos (2005-08-25 14:27:35)


El que pega primero pega dos veces.

#5 2005-08-29 01:34:58

nitrofurano
Novice

Offline

Re: math notation to code notation

thanks! :-)

#6 2005-08-29 23:38:55

John E. Franklin
Guest

Re: math notation to code notation

In C, you can declare variable of various lengths, signed and unsigned numbers.
Some I remember are:  int or integer, long, float, and double.
In C, the complicated math routines are probably in libraries that must be included with a statement like:
#include "C:\BorlandC\stdmath.c"
(I made that last line up.)
I also read that you shouldn't really hard-code paths like above, so better would be:
#include <stdmath.c>
if you can get it to work.  I don't know how to configure the path that way.
Good Luck...

#7 2005-08-30 07:26:30

MathsIsFun
Administrator

Offline

Re: math notation to code notation

That sounds correct, according to my memory of C.

".net" has lots of stuff built in

Javascript has the Math object

Most languages have some math built in, but to do more complicated stuff you gotta get in to some programming.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

#8 2005-09-07 07:17:47

nitrofurano
Novice

Offline

Re: math notation to code notation

Here is an example from formulas i got from an ieee paper about using fractals for compressing pictures
Ieee papers normally talk about algorithms, but only formulas like this are shown - for me who are not comfrotable with math notation is very complicated to try to understand it:
http://img262.imageshack.us/img262/7823/mathnotationfractalpicturecomp.png

are all simple to translate to code notation?

Last edited by nitrofurano (2005-09-07 07:20:28)

#9 2005-09-07 07:50:57

MathsIsFun
Administrator

Offline

Re: math notation to code notation

Math notation is all about concepts. There may or may not be an algorithm, or there could be lots of algorithms!

Being able to turn a concept (expressed in math notation) into a workable algorithm can be an interesting and challenging task! (It is like when a Scientist discovers something, then the Engineer takes over to make it workable)

And, because it is something practical you want to do, you don't have to do everything 100% accurately - speed will be important.

An example is this thread here where a method for calculating cosine is discused - it is only necessary to calculate the first few terms to get a good result.

(BTW, I can see that No 13 is a matrix multiplication, and there are algorithms (and programs) to do that.)


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

#10 2005-09-07 10:38:09

kylekatarn
Power Member

Offline

Re: math notation to code notation

nitrofurano:
all the expressions in the image can be implemented into any computer laguage

most of the formulas seem to be related with sets and matrices so they are very easy to manipulate with a computer.

#11 2005-09-09 06:34:37

nitrofurano
Novice

Offline

Re: math notation to code notation

thanks!!! - btw, if possible,  the point is how can i get to know how can i convert these formulas into algorithms - the standard deviation i knew how to do it, but stuff like calculation integrals and all of these stuff i really don't know - my math notation knowledge got stuck in the middle of highschool, and i choosed fine-arts university, so, during a long time i don't know what is math notation, and that time i had no interest about math notation as i have now (i never thaught those would be helpful for me for picture processing)
Is any open documentation (like from dspace, wikipedia or whatever, or even bibliography) could help me on this task?  or even anyone(s) from this forum can explain how each situation is used in a code notation?
really thanks, for me and all people knows the importance of this help...

Board footer

Powered by FluxBB