S
Schizoid Man
Hello,
I have the following piece of code that uses a one-dimensional root solver
for solve for a particular value. I've currently got this code working by
using a generic public delegate double FX(double x);.
The code looks like:
public static void Main (string[] args)
{
Bond james;
james = new Bond(0.10, 2, 5); // Create a bond - this
constructor forces yield and price of zero
james.BondPrice = 50; // Set the bond price
FX f = delegate(double x)
{
james.BondYield = x;
return (BondPricer.CalcBondPrice(james) - james.BondPrice);
};
double ans = NewtonMethod.DoSolve(f);
Console.WriteLine("Root: {0}", ans);
Console.ReadLine();
}
Could someone give me some tips on how I could convert this using the Func<>
delegate type? I'm interested in writing a couple of other solver classes
and want to keep the delegate declaration as generic as possible (since I'll
be using this to solve for a variety of functions).
Thanks.
I have the following piece of code that uses a one-dimensional root solver
for solve for a particular value. I've currently got this code working by
using a generic public delegate double FX(double x);.
The code looks like:
public static void Main (string[] args)
{
Bond james;
james = new Bond(0.10, 2, 5); // Create a bond - this
constructor forces yield and price of zero
james.BondPrice = 50; // Set the bond price
FX f = delegate(double x)
{
james.BondYield = x;
return (BondPricer.CalcBondPrice(james) - james.BondPrice);
};
double ans = NewtonMethod.DoSolve(f);
Console.WriteLine("Root: {0}", ans);
Console.ReadLine();
}
Could someone give me some tips on how I could convert this using the Func<>
delegate type? I'm interested in writing a couple of other solver classes
and want to keep the delegate declaration as generic as possible (since I'll
be using this to solve for a variety of functions).
Thanks.