# VS2017 CLI question

Greetings,

to make a longs story short i used Fit::Polynomial() for approximation and it worked like a charm.
The results we not ok so my co-worker suggested i use:

y=a0x + a1+ a2x^(-1)+ a3x^(-2)+ a4x^(-3)

Since i use CLI/CLR and the all examples are in C#, i was wondering how do i use Fit::Curve or Fit::LinearCombination(mx, my, MathNet::Numerics::LinearRegression::DirectRegressionMethod::NormalEquations,
////from this point////
t => t, t => 1.0, t => System::Math::Pow(t, -1.0), t => System::Math::Pow(t, -2.0), t => System::Math::Pow(t, -3.0));
////to this point////
How do i write this in CLI language?

I apologise if i did anything wrong, i am very very new to this.
Can anyone help me or point me in the right direction?

Thank you for your time and have a nice day.

Hi, i found out the solution if anyone is interested:

after using namespace copy paste this:
class LambdaRunner
{
function<Double(Double)> _lambda;

``````public:
LambdaRunner(function<Double(Double)> lambda) : _lambda(lambda)
{
}

Double Run(Double n)
{
return _lambda(n);
}
};
ref class RefLambdaRunner
{
LambdaRunner* pLambdaRunner;

Double Run(Double n)
{
return pLambdaRunner->Run(n);
}

public:
RefLambdaRunner(function<Double(Double)> lambda)
{
pLambdaRunner = new LambdaRunner(lambda);
}

Func<Double, Double>^ ToDelegate()
{
return gcnew Func<Double, Double>(this, &RefLambdaRunner::Run);
}

void Close()
{
delete pLambdaRunner;
}
};

auto lambda1 = [](Double z) -> Double { return z; };
auto lambda2 = [](Double z) -> Double { return 1; };
auto lambda3 = [](Double z) -> Double { return System::Math::Pow(z, -1.0); };
auto lambda4 = [](Double z) -> Double { return System::Math::Pow(z, -2.0); };
auto lambda5 = [](Double z) -> Double { return System::Math::Pow(z, -3.0); };
``````

and then copy paste this:

public: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e)
{

``````		cli::array<Double>^ x = gcnew cli::array<Double> {87.0, 151.0, ...(your points) };
cli::array<Double>^ y = gcnew cli::array<Double> {5080.0, 3130.0,  ...(your points)  };
cli::array<Double>^ koef = gcnew cli::array<Double>(5);

auto lambdaRunner1 = gcnew RefLambdaRunner(lambda1);
auto lambdaRunner2 = gcnew RefLambdaRunner(lambda2);
auto lambdaRunner3 = gcnew RefLambdaRunner(lambda3);
auto lambdaRunner4 = gcnew RefLambdaRunner(lambda4);
auto lambdaRunner5 = gcnew RefLambdaRunner(lambda5);

cli::array<System::Func<Double, Double>^>^ fun = gcnew cli::array<System::Func<Double, Double>^>{lambdaRunner1->ToDelegate(), lambdaRunner2->ToDelegate(), lambdaRunner3->ToDelegate(), lambdaRunner4->ToDelegate(), lambdaRunner5->ToDelegate()};
koef = Fit::LinearCombination(x, y, fun);

}``````