View Full Version : Integration

Sang-drax

12-30-2002, 03:39 PM

Which numerical integration method is best to use for an arbitary function of which nothing is known?

Currently I'm using "Simpson's rule", something I found using google. I found something called the "Romberg method" too, but I was unable to find its implementation.

"Simpson's rule" seems quite OK, though.

Secondly, when you are writing math formulas using ascii, how do you write integrals?

Examples:

integrate(f, a,b)

integral{a,b}(f)

§[a,b] f(x)

joshdick

12-31-2002, 12:09 AM

Which numerical integration method is best to use for an arbitary function of which nothing is known? Currently I'm using "Simpson's rule", something I found using google."

That's a good method. The other way I was taught in AP Calc was called the Trapezoidal Rule, but the Simpson's Rule has less of a margin of error; however, it is easier to calculate the margin of error for the Trapezoidal rule. It all depends on how precise you need to be. You could always increase the number of partitions to gain better accuracy.

Secondly, when you are writing math formulas using ascii, how do you write integrals?

Examples:

integrate(f, a,b)

integral{a,b}(f)

§[a,b] f(x)

If you mean in your code, I'd suggest that first one; it's the only one that I think is valid code. If you're outputting the integral, the last one looks the best.

Sang-drax

12-31-2002, 06:53 AM

Originally posted by joshdick

That's a good method. The other way I was taught in AP Calc was called the Trapezoidal Rule,

Yes, I tested the trapezoidal rule and found that it gave much less precision with much more steps.

Originally posted by joshdick

If you mean in your code, I'd suggest that first one; it's the only one that I think is valid code.

The thing is, I'm creating my own programming language (see my sig), and I want the syntax to be as intuitive as possible.

joshdick

12-31-2002, 04:32 PM

Originally posted by Sang-drax

The thing is, I'm creating my own programming language (see my sig), and I want the syntax to be as intuitive as possible.

Wow, man, that's really ambitious. Very cool. I like a lot of your features. It's like you're taking all of the little annoying obstacles in C++ and getting rid of them. In your case, I think that third way looks the nicest. The only thing is, how do type that symbol? I don't think most programmers want to have to hit something like shift+option+ctrl, etc. It looks nice; I think that third way would be nice for output, but I think it'd be bothersome to program that symbol.

Kudos for undertaking such a project. Oh, and what does your signature mean?

Sang-drax

01-01-2003, 09:38 AM

Yes, there's a problem with the '§' character -- it doesn't look the same in a console window and in a windows edit control.

It is quite easy to type on my keyboard (swedish) though.

And my signature?

I found a quote in Latin saying "Quidquid Latine dictum sit, altum videtur", it means "Whatever is said in Latin sounds profound". I used that quote for a while, then I wanted to reduce my sig to one line only.

joshdick

01-01-2003, 09:37 PM

Will your language support OOP?

Sang-drax

01-02-2003, 09:12 AM

That would indeed be nice.

I have been experimenting a little with different syntaxes to implement objects. As I've said, I'd like the syntax to be as easy as possible.

Shiro

01-02-2003, 09:27 AM

>Secondly, when you are writing math formulas using ascii, how

>do you write integrals?

I've used the simulation program PSI a lot, it had an easy, nice and intuitive language.

Integration had the following notation:

y = int (f par: y0);

When writing ASCII integrals in documents I prefer a notation like the one below. For the given integral above it would be:

o-o

/

y = y(0) + | f(x) dx

/

-o-o

>The thing is, I'm creating my own programming language (see

>my sig), and I want the syntax to be as intuitive as possible.

Interesting, what kind of language? A general purpose language? Or mathematical language?

Sang-drax

01-02-2003, 09:36 AM

Originally posted by Shiro

Interesting, what kind of language? A general purpose language? Or mathematical language?

Mainly a mathematical lanuage.

It has built-in support for complex numbers, vectors, matrices, etc.

It is inspired by C++, Pascal and a bit from the TI-83 and Casio calculator languages.

Shiro

01-02-2003, 09:42 AM

In that case you might want to take a look at Matlab. It has a language designed for numerical calculations. For some Matlab examples take a look at:

http://www.cs.uaf.edu/~bueler/MatlabEx.htm

It has some nice constructions for use with matrices and vectors, but it is not always a very intuitive language. The way of for-loops in Matlab is an example of it:

for j = 1:2:n-1

This is the same as:

for (j = 1; j <= n-1; j += 2)

Sang-drax

01-02-2003, 09:54 AM

Originally posted by Shiro

It has some nice constructions for use with matrices and vectors, but it is not always a very intuitive language. The way of for-loops in Matlab is an example of it:

for j = 1:2:n-1

Yes, I've looked at Matlab, although I'm using a program called Mathcad much more. It represents its formulas graphical.

For-loops look like this in Omicron:

for i = 1 ... x+2

//..

next

Shiro

01-02-2003, 10:09 AM

MathCad, I've heard of it, but never used it. But I know it is like Maple, it also gives the graphical representation of formula's, just as you put them to the paper.

The for-loop in Maple is a bit easier to understand, it is like:

for i from 1 by 2 to 100 do print(i) od;

You can also do such like this, combine for with while:

for i from 1 by 2 while i < 100 do print(i) od;

Using words instead of abstract operators is more typing, but in my opinion it is also more intuitive and easier.

BTW, I've been in Växjö last year, but I still don't know how to pronounce it in Swedish? Could you write it phonetic?

Sang-drax

01-02-2003, 05:39 PM

Originally posted by Shiro

BTW, I've been in Växjö last year, but I still don't know how to pronounce it in Swedish? Could you write it phonetic?

You have? Interesting... :D

Are you from the Netherlands?

I remember that my school (Katedralskolan) had an exchange with a school in the Netherlands.

As for the pronounciation of "Växjö":

First sound is a normal 'v'-sound, as in 'vacation' or 'very'

seconly, the same sound as the first sound in 'extra'

then a normal 'k'

then a 'sch'-sound, like the german word 'scheisse'

the last sound is the same as in the german word for oil: 'öl'

stress the first vowel

:D

sean345

01-02-2003, 06:21 PM

Just to say something about integration:

It depends on the function when choosing between Simpson's Rule, Trapezoidal rule, right, left, or middle methods.

On average Simpson's rule is a better estimation. There are some functions though where others will be better. Simpon's Rule creates parabalas and then calculates the area under them. This is based on that any 3 points can be used to create a parabala.

You can calculate the error percent based on the rule. I forgot the exact equations. You can probably find them on-line though. You need to find the point where the second and fourth derivitive diverges to, though. I'm not sure how you could do this in a programming language without a significant amount of calculations.

- Sean

Sang-drax

01-02-2003, 06:30 PM

Originally posted by sean345

You can calculate the error percent based on the rule. I forgot the exact equations. You can probably find them on-line though.

Yeah, here's a good page (PDF)

http://www.eeng.dcu.ie/~ee317/Course_Notes/Numintg.pdf

golfinguy4

01-02-2003, 06:40 PM

Have you considered implementing symbolic support, kinda like on the TI-89? It can keep the answers in terms of variables, and is able to find exact derivates and integrals.

joshdick

01-02-2003, 09:07 PM

Originally posted by Sang-drax

It is inspired by C++, Pascal and a bit from the TI-83 and Casio calculator languages.

The first thing I ever programmed on was a TI-83. There are still a lot of things from that language that I like. A for loop was this easy:

FOR(I,1,10,2)

// is equivalent to

for(i = 1; i <= 10; i+=2)

Aaaaah, that brings back some fond memories of learning to program while bored in the back of my pre-calc class last year.

Anyway, Sang-drax, how do you plan on using this language of yours?

Shiro

01-03-2003, 04:08 AM

As for the pronounciation of "Växjö":

....

Thanks. Yep, last summer I made a trip through Scandinavia with my small tent and car. From Malmö to Stockholm, then to Lappland. From Lappland to Trondheim (N) and via the Hardangervidda and Kristiansand back to the Netherlands, well Fryslân actually.

The â is a character the Dutch don't have, as many characters those poor Dutch don't have. :D

It is pronounced as o, as in mother, thought the Danish write it as å. The y is pronounced as ee in feet, but shorter.

Powered by vBulletin® Version 4.2.5 Copyright © 2019 vBulletin Solutions Inc. All rights reserved.