package piirto; /** * Ohjelmalla integroidaan numeerisesti funktio-olio. * @author Vesa Lappalainen * @version 1.0, 25.03.2003 */ public class Integroi2 { interface FunktioRR { public double f(double x); } public static class SinFun implements FunktioRR { public double f(double x) { return Math.sin(x); } } public static class ExpFun implements FunktioRR { public double f(double x) { return Math.exp(x); } } public static class OmaFun implements FunktioRR { public double f(double x) { return 2*x- 5; } } public static class Poly2 implements FunktioRR { double a,b,c; Poly2(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } public double f(double x) { return a*x*x + b*x + c; } } public static double integroi(FunktioRR f, double x1, double x2, int tiheys) { double x,dx,summa=0; dx = (x2- x1)/tiheys; for (x=x1+dx/2 ; x