0

I am trying to create a big Vandermonde array of Func's. I can create a 4x3 system like this:

Func<double[], double>[] vandermondeSystem =
{
    x =>  x[0]*Math.Pow(1, 0) + x[1]*Math.Pow(1, 1) + x[2]*Math.Pow(1, 2),
    x =>  x[0]*Math.Pow(2, 0) + x[1]*Math.Pow(2, 1) + x[2]*Math.Pow(2, 2),
    x =>  x[0]*Math.Pow(3, 0) + x[1]*Math.Pow(3, 1) + x[2]*Math.Pow(3, 2),
    x =>  x[0]*Math.Pow(4, 0) + x[1]*Math.Pow(4, 1) + x[2]*Math.Pow(4, 2)
}

But it's infeasible to write big (say 100x50) systems like this, so I think I need to use some kind of looping or recursion but I couldn't figure how.

This page explains how to create an anonymous recursion for implementing the Fibonacci function but I couldn't figure out how to utilize the method explained there.

Ferit
  • 8,692
  • 8
  • 34
  • 59
  • 3
    Is it intended that all those functions are identical in your example? – Evk Oct 11 '17 at 09:50
  • the page linked is very explanatory - im just not sure at a glance what your code is trying to do in relation to Vandermonde's matrix – BugFinder Oct 11 '17 at 09:56
  • Vandermonde matrix is a 2d matrix with the terms of a geometric progression in each row. And what is "Vandermonde array of Func's"? – Igor Bendrup Oct 11 '17 at 10:00
  • @Evk I tried to represent 1 +x +x^2 ... 1 +y +y2 ... 1 +z +z^2 etc. – Ferit Oct 11 '17 at 10:14
  • @BugFinder I am tying to create an array of Func's where each Func represents an equation (row) in a Vandermonde system. – Ferit Oct 11 '17 at 10:15
  • @IgorBendrup Func's represent each row (equation) in the system. So array of Func's creates a 2d matrix, which is a Vandermonde system. The reason I want to use Func's is that I have to pass this system to a solver which requires this data structure format. – Ferit Oct 11 '17 at 10:17
  • @Saibot May be i-th Func should be `x => Math.Pow(x[i], 0) + Math.Pow(x[i], 1) + Math.Pow(x[i], 2)` instead of `x => Math.Pow(x[0], 0) + Math.Pow(x[1], 1) + Math.Pow(x[2], 2)`? – Igor Bendrup Oct 11 '17 at 10:36
  • @IgorBendrup Yeah maybe, I'm a bit confused. I intended to create a matrix like 1 + 1+ 1 ... 1 + 2 + 4 ... 1 + 3 + 9 ... 1 + 4 + 16. If you are sure, feel free to edit statements in my question. – Ferit Oct 11 '17 at 10:38
  • @IgorBendrup I was working on it and I found the correct example, so I rejected your edit and edited accordingly. – Ferit Oct 11 '17 at 12:35

1 Answers1

1

Based on your current code, you can easily modify it to support bigger systems of size 100x50 and so on. How about something like this:

Func<double[], double>[] bigVandermondeSystem = new Func<double[], double>[100];

// Constructing a 100 x 50 Vandermonde System
for (int i = 0; i < 100; i++)
{
    var i1 = i;
    bigVandermondeSystem[i] = x => Enumerable
        .Range(0, 50)
        .Sum(number => x[number] * Math.Pow(i1 + 1, number));
}
degant
  • 4,861
  • 1
  • 17
  • 29
  • This worked, but I realized that my example was incorrect, so I edited your solution according to correct example. – Ferit Oct 11 '17 at 12:39
  • @degant I tried to contact you several times but nothing :( I need your mail man if possible – Inside Man May 18 '18 at 17:26