开发者

Implementation of differentiation in C#

I have the following differentiation, I need to implement it in C#:

W(t)=d/dt(log(A(t))开发者_如何学C)

Where A(t) is a array of double data.

How can I obtain the resulting W(t) array from the derivative above?

Thanks

edit:

public double[,] derivative()
{
    dvdt = new double[envelope.GetLength(0), envelope.GetLength(1)];
    int h = 1;

    for (int j = 0; j < envelope.GetLength(0); j++)
    {
        for (int i = 0; i < envelope.GetLength(1)-1 ; i++)
        {
            dvdt[j, i] = (envelope[j, i + h] - envelope[j, i]) / (h);
        }
    }
    return dvdt;
}

I found this library http://autodiff.codeplex.com/ but i cant understand how the sample code is working and how i can apply it to my problem eh


None of this directly addresses your question, but it may help you to get moving again. Getting stuck on trivial items in your thesis can be a royal pain.

Do you have access to Mathematica? Last I checked they had a .NET wrapper around their core engine called .NET/Link.

The performance of Mathematica is stellar. Also, it now supports resources such as GPUs and clusters which could provide a huge performance boost if any of your app lends itself to parallelization.

This would let you focus on the rest of your app instead of having to reinvent the wheel. Also, since you could enter your formulas directly in the Mathematica notebook editor, you could take a more generic, data-driven approach from the C# side.

Here is some typically-impenetrable Wolfram documentation.

See also this thread about parsing Mathematica in C#.

(I only recommend Mathematica because you mentioned that you may need a solver for more than one formula/equation/etc. Unless implementing the solver is a core part of your theses topic, I'd recommend using an off-the-shelf component like this and focusing on your original research.)


Usually you work out the formula for the derivative on your own, and if memory serves d/dx[log_b x] = [1/(x ln b)] dx. If A(t) is a simple array:

double log_b = Math.Log(10); // Assumes Math.Log = ln and b = 10
double dt = 1.0;             // dt is 1 in this case, change if otherwise

double[] W = new double[A.GetLength(0)];
for (int t = 0; t < A.GetLength(0); ++t)
{
    W[t] = dt / (A[t] * log_b);
}


To find the derivative of a logarithmic function:

where y = logb u
dy/dx = logb(e) * u'/u
where u' = du/dx

http://www.intmath.com/differentiation-transcendental/5-derivative-logarithm.php#derivbases

So in order to answer your question, we would need to know the derivative of A(t). If you don't know what A(t) is ahead of time, then you'll need to come up with some kind of generic solver, or require that the input includes both the function A and its derivative.

public double Log10Derivative(Func<double, double> a, 
                              Func<double, double> aPrime, 
                              double t)
{
    return Math.Log10(Math.E) * (aPrime(t) / a(t));
}

As far as performing a log on an array, I either never learned that or I forgot how.

Edit

This should give you an approximation:

public double Log10Derivative(Func<double, double> a, 
                              double t)
{
    const double reallySmallNumber = double.Epsilon;
    var aPrimeEst = (a(t) - a(t + reallySmallNumber)) / reallySmallNumber;
    return Math.Log10(Math.E) * (aPrimeEst / a(t));
}


I think many of the answers are overthinking this. d/dt(log(x)) is just 1/x, so you just need to calculate the reciprocal for each point in the array A.

double[] W = Array.ConvertAll<double, double>(A, x => 1.0 / x);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜