What is the Simpson method and how to implement it in Pascal

Date:

2018-03-18 06:40:50

Views:

821

Rating:

1Like 0Dislike

Share:

Table of contents:

To compute the value of the integral, though approximate, there is a beautiful method, named after its Creator, - Simpson method. It is also called the method of parabolas, because it is a parabola. This figure is constructed as close as possible to the function. In fact, so as to construct a parabola, whose points coincide exactly with the points of the function, is not possible, the integral is approximately. The formula for finding its boundaries a and b looks like this: 1/h*(y0+4y1+2y2+4y3+…+4yN-1+yN). Here we just need to calculate each y from 0 to n, where n we define ourselves – the more, the better, because the more y-s, the more approximate to the true value we get. As for h, then this step and is calculated by the following formula: (b-a)/(n-1).

Simpson method example

In theory it's pretty simple, but would need to implement all this in practice. For many programmers there is no better way to solve this problem, as the method of Simpson – Pascal or Delphi. In this environment it is easy to calculate the integral, and to construct to it the graph of the function, and even built her a trapezoid. So, let's look at how you can quickly implement Simpson method and, if desired, even to explain how here and that organized, to all interested parties.

But before that, remember how it looks integral. This figure, which is bounded by lines starting at the axis x, that is, a and b.

Simpson method

So, to start the program is to create a function for integrable functions (pardon the tautology), in which you just have to write f:= and we will find the integral. It is extremely important not to make mistakes in entering functions in Pascal. But that is a separate topic of conversation. The resulting code will look something like this:

Recommended

How to get out of

How to get out of "Skype" on the "Android" and not only

How to get out of "Skype" "Android"? This question bothers many users. The thing is that the messenger is not so difficult. But there are features that are only for mobile versions. To log out of Skype in this case more difficult than it seems. But i...

Kingo ROOT: how to use the program to gain administrative rights on Android

Kingo ROOT: how to use the program to gain administrative rights on Android

The Gadgets on the platform Android regained the lion's share of the market. Developers are continually perfecting the OS, trying to fit the needs of the users, but from year to year admit palpable mistake: forbid the owner to "stuffing" of his gadge...

How to get from Stormwind to Tanaris: practical tips

How to get from Stormwind to Tanaris: practical tips

World of Warcraft is an iconic MMORPG, uniting millions of players around the world. There are many locations and puzzles, secret trails and larger, but rather dangerous paths. Sooner or later, every player chose the side of the Alliance, we have to ...

Function f(x:real):real;

Main text

Begin

F:=25*ln(x)+sin(10); {here you need to write the contents of your function}

End;

Then write a function to implement Simpson method. It all started like this:

Simpsonmetod function(a,b:real;n:integer):real;

Next, declare the variables:

Var

S:real; { Subtotal (continue) }

H:real; { Step }

My:integer; { Just a counter }

Mno:integer; { Regular multipliers }

And now, in fact, the program itself:

Begin

H:=(b-a)/(n-1); { calculate the step according to the standard formula. Sometimes in the job step is written in this case this formula is not applied }

S:= f(b)+ f(a); { Sets the initial value of the step }

Mno:=4; { Remember the formula 1/h*(y0+4y1… here is the 4 here it is written, the second multiplier will be 2, but more on that next }

Now the same basic formula:

For my:=1 to n-2 do begin

S:=s+mno*f(a+h*mu); { add amount To the next multiplier, multiplied by 4*yN or 2* yN }

If (mno=4) then mno:=2 else mno:=4;{ Here and change the multiplier if it is now equal to 4, then changed to 2 and Vice versa}

End;

Simpsonmetod:=s*h/3; { Then the resulting cycle is the sum multiplied by h/3 according to the formula}

End.

That was it – do all actions in accordance with the formula. If you still do not understand how to apply in the main program Simpson method, an example will help you with this.

So after writing all write functions

Begin

N:=3; { Set n }

Q:=simpsonmetod(a,b,n); { since the Simpson method is to calculate the integral from a to b, there will be several calculation steps, so make a loop }

Repeat

Q2:=q; { Remember previous step }

N:=n+2;

Q:=simpsonmetod(a,b,n); { calculated value }

Until (abs(q-q2)<0.001);{ written task accuracy, and therefore not yet reached the required accuracy, it is necessary to repeat the same steps }

Simpson method Pascal

Here's a he-Simpson method. In fact, nothing complicated, all written very quickly! Now open your Turbo Pascal and start writing the program.


Article in other languages:

AR: https://tostpost.com/ar/computers/6896-what-is-the-simpson-method-and-how-to-implement-it-in-pascal.html

BE: https://tostpost.com/be/kamputary/12329-u-chym-zaklyuchaecca-metad-s-mpsana-yak-real-zavac-yago-na-move-paskal.html

DE: https://tostpost.com/de/computer/12331-was-ist-die-simpson-methode-und-implementieren-es-in-der-sprache-pasca.html

ES: https://tostpost.com/es/los-ordenadores/12339-en-que-consiste-el-m-todo-de-simpson-y-c-mo-implementar-en-pascal.html

HI: https://tostpost.com/hi/computers/6902-what-is-the-simpson-method-and-how-to-implement-it-in-pascal.html

JA: https://tostpost.com/ja/computers/6900-what-is-the-simpson-method-and-how-to-implement-it-in-pascal.html

KK: https://tostpost.com/kk/komp-yuterler/12332-nede-d-s-simpson-zh-ne-ony-paskal.html

PL: https://tostpost.com/pl/komputery/12325-na-czym-polega-metoda-simpsona-i-jak-wdro-y-go-w-j-zyku-pascal.html

PT: https://tostpost.com/pt/computadores/12320-em-que-consiste-o-m-todo-de-simpson-e-como-implement--lo-em-linguagem-.html

TR: https://tostpost.com/tr/bilgisayarlar/12334-nedir-y-ntem-simpson-ve-uygulamak-onun-dilinde-pascal.html

UK: https://tostpost.com/uk/komp-yuteri/12332-u-chomu-polyaga-metod-s-mpsona-yak-real-zuvati-yogo-na-mov-paskal.html

ZH: https://tostpost.com/zh/computers/7476-pascal.html






Alin Trodden - author of the article, editor
"Hi, I'm Alin Trodden. I write texts, read books, and look for impressions. And I'm not bad at telling you about it. I am always happy to participate in interesting projects."

Comments (0)

This article has no comment, be the first!

Add comment

Related News

Games similar to

Games similar to "Nancy drew": the list

"Nancy drew" is a fascinating adventure game created for the PC platform. The history of this for almost 10 years, and she still does not lose relevance. The game is created on motives of a series of books about the girl detective...

System programs for PC

System programs for PC

Quite often, many users of computer systems are faced with the question of what constitutes the system programs. With the knowledge of how they work and proper use you can achieve a lot, well, at least to avoid the appearance of e...

The installation of

The installation of "Sims 4": how to run the game

Installing "the Sims 4" is a pretty simple process if you know which side to approach him. However, there are some difficulties that are mostly waiting for fans of "piratok". So let's see how to install "the Sims 4" and run it.the...

The best alternative to iTunes: a review of programs

The best alternative to iTunes: a review of programs

With the development of the tech guys from Silicon valley are trying to create more useful software for the user. Some programs cease to be relevant for many reasons. Someone buys a new device that does not support more need softw...

Detailed walkthrough Styx: Master of Shadows

Detailed walkthrough Styx: Master of Shadows

Today we consider the passage of Styx: Master of Shadows. We are talking about exciting game, the main story campaign which will be in detail described below.PastWalkthrough Styx: Master of Shadows begins with the interrogation of...

World of Tanks: fashion prohibited by the developers

World of Tanks: fashion prohibited by the developers

the Popular Russian game World of Tanks draws an audience of all ages. Due to this, she had her own komyuniti, which helps the project grow in the right direction. However, not all ideas gamers are reflected in the official public...