import fi.jyu.mit.ohj2.*; /** * Ohjelmalla integroidaan numeerisesti funktio-olio. * @author Vesa Lappalainen * @version 1.0, 25.03.2003 */ public class Integroi2 { interface FunktioRR { public double f(double x); } static class SinFun implements FunktioRR { public double f(double x) { return Math.sin(x); } } static class ExpFun implements FunktioRR { public double f(double x) { return Math.exp(x); } } static class OmaFun implements FunktioRR { public double f(double x) { return 2*x- 5; } } static class P2 implements FunktioRR { private double a,b,c; public P2(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 String toString() { return a + "x^2 + " + 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