@@ -10,9 +10,6 @@ public abstract partial class Entity
1010 /// <summary>
1111 /// Returns a value of a definite integral of a function. Only works for one-variable functions
1212 /// </summary>
13- /// <param name="func">
14- /// Function with only one variable
15- /// </param>
1613 /// <param name="x">
1714 /// Variable to integrate over
1815 /// </param>
@@ -23,17 +20,14 @@ public abstract partial class Entity
2320 /// The up bound for integrating
2421 /// </param>
2522 /// <returns></returns>
26- public Number DefiniteIntegral ( Entity func , VariableEntity x , Number from , Number to )
23+ public Number DefiniteIntegral ( VariableEntity x , Number from , Number to )
2724 {
28- return Integration . Integrate ( func , x , from , to , 100 ) ;
25+ return Integration . Integrate ( this , x , from , to , 100 ) ;
2926 }
3027
3128 /// <summary>
3229 /// Returns a value of a definite integral of a function. Only works for one-variable functions
3330 /// </summary>
34- /// <param name="func">
35- /// Function with only one variable
36- /// </param>
3731 /// <param name="x">
3832 /// Variable to integrate over
3933 /// </param>
@@ -47,9 +41,9 @@ public Number DefiniteIntegral(Entity func, VariableEntity x, Number from, Numbe
4741 /// Accuracy (initially, amount of iterations)
4842 /// </param>
4943 /// <returns></returns>
50- public Number DefiniteIntegral ( Entity func , VariableEntity x , Number from , Number to , int stepCount )
44+ public Number DefiniteIntegral ( VariableEntity x , Number from , Number to , int stepCount )
5145 {
52- return Integration . Integrate ( func , x , from , to , stepCount ) ;
46+ return Integration . Integrate ( this , x , from , to , stepCount ) ;
5347 }
5448 }
5549 public static class Integration
@@ -61,11 +55,12 @@ public static Number Integrate(Entity func, VariableEntity x, Number from, Numbe
6155 double ReTo = to . Re ;
6256 double ImTo = to . Im ;
6357 var res = new Number ( 0 , 0 ) ;
58+ var cfunc = func . Compile ( x . Name ) ;
6459 for ( int i = 0 ; i <= stepCount ; i ++ )
6560 {
6661 var share = ( ( double ) i ) / stepCount ;
6762 var tmp = new Number ( ReFrom * share + ReTo * ( 1 - share ) , ImFrom * share + ImTo * ( 1 - share ) ) ;
68- res += func . Substitute ( x , tmp ) . Eval ( ) . GetValue ( ) ;
63+ res += cfunc . Eval ( tmp ) ;
6964 }
7065 return res / ( stepCount + 1 ) * ( to - from ) ;
7166 }
0 commit comments