/*
 * Created on Jan 26, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author User
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class FlowFunction implements MathFunction, MathFunction2 
{
    double s, n, w, Q, kappa;
    public FlowFunction(double s, double n, double w, double Q)
    {
        this.s = s;
        this.n = n;
        this.w = w;
        this.Q = Q;
        
        kappa = Math.sqrt(s)/n*Math.pow(w,5.0/3.0);
    }
    
    public double f(double d)
    {
        return (kappa*Math.pow(d,5.0/3.0)/Math.pow(d+2.0*w,2.0/3.0) - Q);
    }
    
    public double fn(double d)
    {
        return f(d);
    }
    
    
    public double fd(double d)
    {
        return (kappa/3.0*(5.0*Math.pow(d/(d+2.0*w),2.0/3.0)-2.0*Math.pow(d/(d+2.0*w),5.0/3.0)));
    }
    
    public double velocity(double d)
    {
        return (Math.sqrt(s)/n*Math.pow(d*w/(d+2.0*w),2.0/3.0));
    }
    
}
