You are on page 1of 3

C:\Users\Cengiz\Desktop\Program.

cs 1
1 using System;
2
3 namespace Chapter09_CodeExamples
4 {
5 class Program
6 {
7 //public static double x { get; private set; }
8 //private static double x;
9 public delegate double Function(double x);
10 private static double S = 0.7264;
11 private static double span = 300.0 / 0.3048;
12 private static double w = 1.094;
13 private static int Tini = 6300;
14 private static double eten = 0.133881314;
15 private static double es = 100.0 * (2.0 * Tini / w * Math.Sinh(w *
span / 2.0 / Tini) / span ­ 1.0);
16 private static double A0 = ­1213.0;
17 private static double A1 = 44308.1;
18 private static double A2 = ­14004.4;
19 private static double A3 = ­37618.0;
20 private static double A4 = 30676.0;
21 private static double B0 = ­69.3;
22 private static double B1 = 38629.0;
23 private static double B2 = 3998.1;
24 private static double B3 = ­45713.0;
25 private static double B4 = 27892.0;
26 private static double alten0 = S * (A0 + A1 * 0.5 + A2 * 0.5 *0.5 + A3
* 0.5*0.5*0.5 + A4 * 0.5*0.5*0.5*0.5);
27 private static double coreten0 = S * (B0 + B1 * 0.5 + B2 * 0.5*0.5 + B3
* 0.5*0.5*0.5 + B4 * 0.5*0.5*0.5*0.5);
28 private static double dalini = A1 + 2 * A2 * 0.5 + 3 * A3 * 0.5 *0.5 +
A4 * 0.5 *0.5*0.5;
29 private static double dcoreini = B1 + 2 * B2 * 0.5 + 3 * B3 * 0.5 *0.5
+ B4* 0.5 *0.5*0.5;
30 private static double er = es ­ eten;
31 private static double wice = 2.51010217064904;
32 private static double wicetemp = ­20.0;
33 private static double reftemp = 21.1;
34 private static double cteal = 0.00128 * 9.0 / 5.0 / 100.0;
35 private static double ctecore = 0.00064 * 9.0 / 5.0 / 100.0;
36 private static double altempstrain = cteal * (wicetemp ­ reftemp) *
100.0;
37 private static double coretempstrain = ctecore * (wicetemp ­ reftemp) *
100.0;
38 private static double alT = S * (A0 + A1 * 0.5 + A2 * 0.5 * 0.5 + A3 *
0.5 * 0.5 * 0.5 + A4 * 0.5 * 0.5 * 0.5 * 0.5);
39 private static double dalT = 1 * (A1 + 2 * A2 * 0.5 + 3 * A3 * 0.5 *0.5
+ 4 * A4 * 0.5 * 0.5 * 0.5);
40 private static double coreT = S * (B0 + B1 * 0.5 + B2 * 0.5 * 0.5 + B3
* 0.5 * 0.5 * 0.5 + B4 * 0.5 * 0.5 * 0.5 * 0.5);
41 private static double dcoreT = 1 * (B1 + 2 * B2 * 0.5 + 3 * B3 * 0.5
*0.5 + 4 * B4 * 0.5 * 0.5 * 0.5);
42
43 #region Newton­Raphson Method
44 public static double NewtonRaphsonMethod(Function f, Function fprime,
double x0, double epsilon)
C:\Users\Cengiz\Desktop\Program.cs 2
45 {
46 double f0 = f(x0);
47 double x = x0;
48 while (Math.Abs(f(x)) > epsilon)
49 {
50 x ­= f0 / fprime(x);
51 f0 = f(x);
52 }
53 return x;
54 }
55 #endregion
56
57 #region Test Functions
58 static double F1(double x)
59 {
60 double xal = 200.0 * x / span / wice * Math.Sinh(span * wice /
2.0 / x) ­ 100.0 ­ er ­ altempstrain;
61 double xcore = (((200 * x / span / wice) * Math.Sinh(span * wice /
2 / x)) ­ 100 ­ er ­ coretempstrain);
62 return S * (A0 + A1 * xal + A2 * xal * xal + A3 * xal * xal * xal +
A4 * xal * xal * xal * xal) + S * (B0 + B1 * xcore + B2 * xcore
* xcore + B3 * xcore * xcore * xcore + B4 * xcore * xcore * xcore
* xcore) ­ x;
63 }
64 static double F1prime(double x)
65 {
66 return S * (A1 * (200.0 * Math.Sinh(span * wice / 2.0 / x) / span /
wice ­ 100.0 * Math.Cosh(span * wice / 2.0 / x) / x) + 2.0 * A2
* (200.0 * Math.Sinh(span * wice / 2.0 / x) / span / wice ­ 100.0
* Math.Cosh(span * wice / 2.0 / x) / x) * (­100.0 ­ altempstrain
­ er + 200.0 * x * Math.Sinh(span * wice / 2.0 / x) / span /
wice) + 3.0 * A3 * (200.0 * Math.Sinh(span * wice / 2.0 / x) /
span / wice ­ 100.0 * Math.Cosh(span * wice / 2.0 / x) / x) *
(­100.0 ­ altempstrain ­ er + 200.0 * x * Math.Sinh(span * wice /
2.0 / x) / span / wice) * (­100.0 ­ altempstrain ­ er + 200.0 *
x * Math.Sinh(span * wice / 2.0 / x) / span / wice) + 4.0 * A4 *
(200.0 * Math.Sinh(span * wice / 2.0 / x) / span / wice ­ 100.0 *
Math.Cosh(span * wice / 2.0 / x) / x) * (­100.0 ­ altempstrain ­
er + 200.0 * x * Math.Sinh(span * wice / 2.0 / x) / span / wice)
* (­100.0 ­ altempstrain ­ er + 200.0 * x * Math.Sinh(span *
wice / 2.0 / x) / span / wice) * (­100.0 ­ altempstrain ­ er +
200.0 * x * Math.Sinh(span * wice / 2.0 / x) / span / wice)) + S
* (B1 * (200.0 * Math.Sinh(span * wice / 2.0 / x) / span / wice ­
100.0 * Math.Cosh(span * wice / 2.0 / x) / x) + 2 * B2 * (200.0
* Math.Sinh(span * wice / 2.0 / x) / span / wice ­ 100.0 *
Math.Cosh(span * wice / 2.0 / x) / x) * (­100.0 ­ altempstrain ­
er + 200.0 * x * Math.Sinh(span * wice / 2.0 / x) / span / wice)
+ 3 * B3 * (200.0 * Math.Sinh(span * wice / 2.0 / x) / span /
wice ­ 100.0 * Math.Cosh(span * wice / 2.0 / x) / x) * (­100.0 ­
altempstrain ­ er + 200.0 * x * Math.Sinh(span * wice / 2.0 /
x) / span / wice) * (­100.0 ­ altempstrain ­ er + 200.0 * x *
Math.Sinh(span * wice / 2.0 / x) / span / wice) + 4.0 * B4 *
(200.0 * Math.Sinh(span * wice / 2.0 / x) / span / wice ­ 100.0 *
Math.Cosh(span * wice / 2.0 / x) / x) * (­100.0 ­ altempstrain ­
er + 200.0 * x * Math.Sinh(span * wice / 2.0 / x) / span / wice)
* (­100.0 ­ altempstrain ­ er + 200.0 * x * Math.Sinh(span *
C:\Users\Cengiz\Desktop\Program.cs 3
wice / 2.0 / x) / span / wice) * (­100.0 ­ altempstrain ­ er +
200.0 * x * Math.Sinh(span * wice / 2.0 / x) / span / wice))
­1.0;
67 }
68 #endregion
69
70 static void Main(string[] args)
71 {
72 try
73 {
74 Console.WriteLine("\n\nTesting Newton­Raphson Method\n");
75 double x = NewtonRaphsonMethod(F1, F1prime, 10000.0,
0.00000001);
76 Console.WriteLine("Solution from the Newton­Raphson method: " +
x.ToString());
77 Console.WriteLine("Solution confirmation: f(x) = " + F1
(x).ToString());
78 Console.ReadLine();
79 }
80 catch (Exception ex)
81 {
82 Console.WriteLine("Fatal error: " + ex.Message);
83 Console.ReadLine();
84 }
85 }
86 }
87 }
88

You might also like