/// <summary> /// Calculates the surface area under z = fxy(x,y) from y=f(x) to y=g(x) and x=a to x=b. /// </summary> /// <param name="fxy">The function f(x,y).</param> /// <param name="f">The function f(x).</param> /// <param name="g">The function g(x).</param> /// <param name="a">The lower limit.</param> /// <param name="b">The upper limit.</param> /// <param name="m">The m.</param> /// <param name="n">The n.</param> public static double SurfaceArea2D(Functionxy fxy, Function f, Function g, double a, double b, int m, int n) { Integral intMethod = GaussianRuleIntetration(); return(DoubleIntegration((double x, double y) => Math.Sqrt(1 + Math.Pow(PartialDifferentiationx(fxy, x, y), 2) + Math.Pow(PartialDifferentiationy(fxy, x, y), 2)), f, g, a, b, m, n, intMethod, intMethod)); }
public static double SurfaceArea3D(Functionxy fxyz, Function f, Function g, Function h, Function i, double a, double b, int m, int n)// needs finishing. { Integral3 intMethod = GaussianRuleIntetration3(); //return TripleIntegration((double x, double y, double z) => //Math.Sqrt(1 + Math.Pow(PartialDifferentiationx(fxyz, x, y), 2) + Math.Pow(PartialDifferentiationy(fxyz, x, y), 2) + Math.Pow(PartialDifferentiationz(fxyz, x, z), 2) + Math.Pow(PartialDifferentiationz(fxyz, y, z), 2)), f, g, i, a, b, m, n, intMethod, intMethod); return(0); }
/// <summary> /// A fourth order Runge-Kutta method for y'=f(t,y), first order ode in the interval (a,b) with a given initial condition at x=a and fixed step h. /// </summary> /// <param name="f">The function.</param> /// <param name="a">The beginning of the interval.</param> /// <param name="b">The end of the interval.</param> /// <param name="value">The initial condition, where x=a.</param> /// <param name="step">The fixed step, or h.</param> public double RungeKutta(Functionxy f, double a, double b, double value, double step) { var t = a; var w = value; for (var i = 0; i < (b - a) / step; i++) { var k1 = step * f(t, w); var k2 = step * f(t + step / 2, w + k1 / 2); var k3 = step * f(t + step / 2, w + k2 / 2); var k4 = step * f(t + step, w + k3); w = w + (k1 + 2 * k2 + 2 * k3 + k4) / 6; t = a + i * step; //Console.WriteLine("{0} {1} ", t, w); } return(w); }
// Double integration using nested lambda functions - method below could be extended to 3D or higher integration. /// <summary> /// 2D integration of a function of 2 variables. (( f(x,y)dxdy )). /// </summary> /// <param name="fxy">The fxy.</param> /// <param name="g">The g.</param> /// <param name="h">The h.</param> /// <param name="a">A.</param> /// <param name="b">The b.</param> /// <param name="m">The m.</param> /// <param name="n">The n.</param> /// <param name="inInt">The in int.</param> /// <param name="outInt">The out int.</param> /// <remarks>Inner integral dx, from x=g(y) to x=h(y), over m subintervals, using algorithm inInt. /// Outer integral dy, from y=a to y=b, over n subintervals, using algorithm outInt.</remarks> public static double DoubleIntegration(Functionxy fxy, Function g, Function h, double a, double b, int m, int n, Integral inInt, Integral outInt) { return(outInt((double y) => inInt((double x) => fxy(x, y), g(y), h(y), m), a, b, n)); }
/// <summary> /// Partial differentiation of z. /// </summary> /// <param name="fxy">The function f(x,y).</param> /// <param name="a">The parameter a.</param> /// <param name="b">The parameter b.</param> public static double PartialDifferentiationz(Functionxy fxy, double a, double b) { Differentiation diff = D2PointCenter(); // Could be a parameter. return(diff((double z) => fxy(a, z), b)); }