Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,
I am solving Manning Equation in C# ,but facing problem in implementing Differentiation to the below

f(y)=[ (nq/(c2*s0^(1/2)))3/5)*(c2/c1)]5/8 to f'(y).

i am doing this in console application.can anyone help me with this please.


EDIT: AL
Added code from comments:


sir sorry ,i am not troubling i think ,

this the whole code of my project
and this is the class file
Equation1.cs

C#
public double Find_C1(int Z1,int Z2) 
{
  return (Z1 + Z2) / 2;
}
public double Find_C2(int Z1,int Z2)
{
  return c1=Math.Pow(((1 + Math.Pow(Z1, 2))), 0.5) + Math.Pow(((1 + Math.Pow(Z2, 2))), 0.5);

}
public double Aofy(int y,int b,double c1) 
{

  return a=((b + c1) * y) * y;
}
public double PofY(int y, int b, double c2) 
{
  return p = b +(c2 * y);
}
public double RofY(int y, int b, int c2) 
{
  return a / p;
}
public double find_V(double s0, double n, double R) 
{
  double v= (Math.Pow(s0,0.5) / n) * Math.Pow(R,0.66);
  return v;
}
public double find_q(double a,double v) 
{
  return a * v;
}
public double find_F(double n, double q, double c2, double s0, double c1) 
{
  double f;

  return f= Math.Pow((Math.Pow(((n * q) / (c2 * (Math.Pow(s0, 0.5)))), 0.6)) * (c2 / c1), 0.625);

}

and in main i am calling it as
C#
class Program
{
  static void Main(string[] args)
  { 
    Equation1 obj = new Equation1();
    Console.WriteLine(string.Format("Enter S0"));
    s0 = double.Parse(Console.ReadLine());
    Console.WriteLine(string.Format("Enter Z2"));
    Z2 = int.Parse(Console.ReadLine());
    Console.WriteLine(string.Format("Enter Z1"));
    Z1 = int.Parse(Console.ReadLine());
    Console.WriteLine(string.Format("Enter Y"));
    y = int.Parse(Console.ReadLine());
    Console.WriteLine(string.Format("Enter b"));
    b = int.Parse(Console.ReadLine());


    Console.WriteLine(string.Format("C1:{0}",obj.Find_C1(Z1, Z2)));
    Console.WriteLine(string.Format("C2:{0}", obj.Find_C2(Z1,Z2)));
   Console.WriteLine(string.Format("A(y):{0}",(b+(obj.Find_C1(Z1, Z2)*y))*y));
   Console.WriteLine(string.Format("P(y):{0}",(b+ (obj.Find_C2(Z1, Z2)*y))));
   Console.WriteLine(string.Format("R(y):{0}", ((b + (obj.Find_C1(Z1, Z2) * y)) * y) / (b + (obj.Find_C2(Z1, Z2) * y))));
   Console.WriteLine(string.Format("V:{0}", obj.find_V(s0,0.1,Math.Pow((((b+(obj.Find_C1(Z1, Z2)*y))*y)/(b+ (obj.Find_C2(Z1, Z2)*y))),2/3))));
   Console.WriteLine(string.Format("Q:{0}",obj.find_q(obj.Aofy(y, b, obj.Find_C1(Z1, Z2)), obj.find_V(s0, 0.1, Math.Pow((((b + (obj.Find_C1(Z1, Z2) * y)) * y) / (b + (obj.Find_C2(Z1, Z2) * y))), 2 / 3)))));


//F is Wrong
   Console.WriteLine(string.Format("F:{0}", obj.find_F(0.1, obj.find_q(obj.Aofy(y, b, obj.Find_C1(Z1, Z2)), obj.find_V(s0, 0.1, Math.Pow((((b + (obj.Find_C1(Z1, Z2) * y)) * y) / (b + (obj.Find_C2(Z1, Z2) * y))), 2 / 3))), obj.Find_C2(Z1, Z2), s0, obj.Find_C1(Z1, Z2))));
   Console.ReadLine();

}

public static double s0 { get; set; }

public static int Z2 { get; set; }

public static int Z1 { get; set; }

public static int y { get; set; }

public static int b { get; set; }
}
Posted
Updated 27-May-15 4:37am
v2
Comments
RAJU-11052090 27-May-15 9:19am    
sir there are several related expression like


to find Q=A*V
V=((S0)1/2/n)*R2/3
A=(b+c1y)y

C2=(1+(Z1)^2)^1/2 + (1+(Z2)^2)^1/2
C1=(Z1+Z2)/2


i am calculating all these separately and directly substituting the values

and S0,n,b,Z1,Z2 all are constants.
Andy Lanng 27-May-15 9:35am    
You have to reply to my comment or I don't get notified that you have replied.

That's great, but show us some code. Click the 'Improve Question' button and add some code to the question ^_^
RAJU-11052090 27-May-15 9:51am    
ok sir i'll
RAJU-11052090 27-May-15 9:51am    
to find A

public double Aofy(int y,int b,double c1)
{

return a=((b + c1) * y) * y;
}

1 solution

I got it. Thanks for posting the code. I know the error:


ints are problematic. you would think that (1/2) would equal 0.5? well c# says it's 1.


operations on ints returns an int.

C#
//Every time z1+z2 is odd, you will lose precision.
public double Find_C1(int Z1, int Z2)
{
   return (Z1 + Z2) / 2;
}


//Try this:
public double Find_C1(int Z1, int Z2)
{
   return ((double)(Z1 + Z2)) / 2.0;
}

//also in main:
...
Console.WriteLine(string.Format("V:{0}", obj.find_V(s0, 0.1, Math.Pow((((b + (obj.Find_C1(Z1, Z2) * y)) * y) / (b + (obj.Find_C2(Z1, Z2) * y))), 2 / 3))));
//2 / 3 = 1, not 0.66.
// try 2.0 / 3.0
...

Console.WriteLine(string.Format("V:{0}", obj.find_V(s0, 0.1, Math.Pow((((b + (obj.Find_C1(Z1, Z2) * y)) * y) / (b + (obj.Find_C2(Z1, Z2) * y))), 2.0 / 3.0))));
//the 2/3 appears a few time so make sure you catch them all


hope that helps ^_^


also - this is the iterative process to find yn to a tolerance of 0.0001:
C#
double nextY = 0.0;
double thisY = y;
double tolerance = thisY - nextY;
while (tolerance > 0.0001)
{
    nextY = obj.find_F(0.1, obj.find_q(obj.Aofy(y, b, obj.Find_C1(Z1, Z2)), obj.find_V(s0, 0.1, Math.Pow((((b + (obj.Find_C1(Z1, Z2) * y)) * y) / (b + (obj.Find_C2(Z1, Z2) * y))), 2.0 / 3.0))), obj.Find_C2(Z1, Z2), s0, obj.Find_C1(Z1, Z2));
    tolerance = thisY - nextY;
    if (tolerance < 0.0)
    {
        tolerance = -tolerance;
    }
        thisY = nextY;
}




//F is Wrong
Console.WriteLine(string.Format("F:{0}", thisY)); ;
Console.ReadLine();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900