Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**Nitrofu****Guest**

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

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,569

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

Offline

**nitrofurano****Member**- Registered: 2005-08-13
- Posts: 4

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

```
'- 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

Offline

**ryos****Member**- Registered: 2005-08-04
- Posts: 394

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-24 16:27:35)*

El que pega primero pega dos veces.

Offline

**nitrofurano****Member**- Registered: 2005-08-13
- Posts: 4

thanks! :-)

Offline

**John E. Franklin****Guest**

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...

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,569

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

Offline

**nitrofurano****Member**- Registered: 2005-08-13
- Posts: 4

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:

are all simple to translate to code notation?

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

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,569

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

Offline

**kylekatarn****Member**- Registered: 2005-07-24
- Posts: 445

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.

Offline

**nitrofurano****Member**- Registered: 2005-08-13
- Posts: 4

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...

Offline

Pages: **1**