I am implementing an algorithm for school and am having problems understanding how a definite integral is represented in programming. For example I know that the Summation equation can be implemented as the following example:
assuming y=f(x)
if(x==0){
y=x+1;
}else{
for(int i = 0; i < n; i++){
y = y + (x - 1);
}
}
How would I then represent a numerical integral, example:
The equations planted here may not make mathematical sense but my objective is to implement similar equations in c# for a school programming project that I have to do in which I have to implement an algorithm which contains integrals. I have been reading that there are numerical methods to solve definite integrals such as simpson rule; would I have to use such methods to implement the equation or can an integral be represented in programming such as a loop or something of that sort?
Those who understand equations behind programming languages will easily comprehend their structure, which will come in handy later when some actual programming starts to take shape.
Mathematical programming refers to mathematical models used to solve problems such as decision problems. The terms are meant to contrast with computer programming which solves such problems by implementing algorithms which may be designed specifically for a given problem.
This field of mathematics is also utilized in a wide array of programming areas such as making visuals or graphs, simulations, coding-in applications, problem-solving applications, analysis and design of algorithms, and making statistic solvers.
A really great resource is a book called Competitive Programming 3 the book is great overall, and most importantly the Math chapter in it. The authors have really gathered a lot of Math-related problems and if you solve just a few you will definitely improve your Math and Problem Solving skills.
It depends on what you are trying to do. If this was a specific implementation you could simply integrate the formula x-1
becomes (x^2)/2 - x
and then return the max value minus the minimum value.
Alternatively it can be implemented as an estimation choosing an appropriate step size for dx.
decimal dx=0.1;
if(x==0){
y=x+1; // could just return y=1
}else{
decimal tempY=0;
for(decimal i = 3; i <= 20; i+=dx){
tempY += (i - 1);
}
// Either return tempY as decimal or
y= Convert.ToInt32(tempY);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With