Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Riemann Sums
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public delegate double Function(double x); public static void Main(string[] args) { Function xInt = (x) => {return x;}; Function overXInt = (x) => {return 1.0/x;}; LeftRiemannSum(overXInt, 1, Math.E, 10000); RightRiemannSum(overXInt, 1, Math.E, 10000); MeanRiemannSum(overXInt, 1, Math.E, 10000); } public static double LeftRiemannSum(Function func, double start, double end, int steps) { double diff = end - start; double dx = diff/(double)steps; double F = 0; for(int i = 0; i < steps; i++) { F += func(start + (double)i*dx)*dx; //Console.WriteLine(F); } Console.WriteLine("F(x) from " + start + " to " + end + " is " + F); return F; } public static double RightRiemannSum(Function func, double start, double end, int steps) { double diff = end - start; double dx = diff/(double)steps; double F = 0; for(int i = 1; i < steps+1; i++) { F += func(start + (double)i*dx)*dx; //Console.WriteLine(F); } Console.WriteLine("F(x) from " + start + " to " + end + " is " + F); return F; } public static double MeanRiemannSum(Function func, double start, double end, int steps) { double F = (RightRiemannSum( func, start, end, steps) + LeftRiemannSum( func, start, end, steps))/2.0; Console.WriteLine("F(x) from " + start + " to " + end + " is " + F); return F; } } }
run
|
edit
|
history
|
help
0
4647
I have a small friend
bubbleSort
c++
1. Basics: primitive data types
enums with extension method: better
blanaced parenthes
Hello world
Get missed element in integer collection
ArrayList list merge_collections