How can I raise Math.E to an array?

-1

I have used this code but it does not let me raise the number e to an array nor with Math.Pow() , Math.exp() . How can I do it?? here I leave code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Symbolics;
using MathNet.Numerics.RootFinding;
using NMath;
using MathNet.Filtering.Kalman;
using System.Runtime;
using NLapack.Matrices;
using NLapack.Numbers;


namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            double omega = 2 * Math.PI / 24;
            double omegacua = Math.Pow(omega, 2);

            Matrix<double> Ac = DenseMatrix.OfArray(new double[,] { { 0, 1, 0, 0 }, { (-1 * omegacua), 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } });

            Matrix<double> A = Math.Exp(Ac);

        }
    }
}
    
asked by Juan 17.12.2018 в 10:33
source

1 answer

1

If we analyze the documentation

Math.Exp (Double) Method

You will notice that the method expects a data of type double , not a matrix

That's why in order for it to work you should iterate every item of the matrix and perform the calculation

Matrix<double> A = new Matrix<double>[Ac.GetLength(0), Ac.GetLength(1)];
int i = 0;
foreach(var item in Ac){
  int j=0;
  foreach(var item1 in item){
    A[i,j] = Math.Exp(item1);
    j++;
  }
  i++;
}

Using foreach with arrays (C # Programming Guide)

The idea is to calculate for each value of the matrix iterating it

    
answered by 17.12.2018 в 12:04