



import static java.lang.Math.*;

/**
 * @author sg
 */
public class LinearFDMTest {

	public static void main(String[] args) {
		double xa=1, ya=1, xb=2, yb=2;
		int n=10;
		
		Function1 exact=new Function1(){
			private double c2=(8-12*sin(log(2))-4*cos(log(2)))/70;
			private double c1=(11/10.0)-c2;
			public double f(double x) {
				return c1*x+c2/(x*x)-(3*sin(log(x)))/10-cos(log(x))/10;
			}
			
		};
		
		double[] resEx = new double[n+1];
		double h = (xb - xa) / n;
		double x=xa;
		for (int i = 0; i <= n; i++) {
			resEx[i] = exact.f(x);
			x += h;
		}
		
		Function1 p = new Function1() {
			public double f(double x) {
				return -2 / x;
			}
		};

		Function1 q = new Function1() {
			public double f(double x) {
				return 2 / (x*x);
			}
		};

		Function1 r = new Function1() {
			public double f(double x) {
				return  sin(log(x))/ (x*x);
			}
		};
		
		System.out.println("Differenzenmethode:");
		LinearFDM fdm=new LinearFDM();
		double[] sol=fdm.solve(p, q, r, xa,ya,xb,yb, n);
		for(int i=0; i<sol.length; i++){
			System.out.format("%1$5.12f   %2$5.12f   %3$5.12f\n", sol[i], resEx[i], sol[i] - resEx[i]);
		}
		

	}
}
