[英]C# Mathnet Numerics Polynomial Evaluate across an vector/array, do I have to loop?
Ok, so I'm attempting to fumble my way through a Matlab source code conversion into C#.好的,所以我试图通过将 Matlab 源代码转换为 C# 来摸索。 Thus far I've been able to do everything without needing to implement any loops.到目前为止,我已经能够在不需要实现任何循环的情况下完成所有工作。
data = vector of data Fourier.Forward(data.AsArray()) takes in data and overwrites the original vector with the results. data = 数据向量 Fourier.Forward(data.AsArray()) 接收数据并用结果覆盖原始向量。 Vector.ABS(data) calculates the absolute value across the vector Polynomial.Fit(x.AsArray(), data.Array()) calculates and returns the coefficients for the polynomial Vector.ABS(data) 计算向量的绝对值 Polynomial.Fit(x.AsArray(), data.Array()) 计算并返回多项式的系数
but now I need to plot and find the Y value based on the X. The only function I can find is但现在我需要根据 X 绘制并找到 Y 值。我能找到的唯一函数是
Polynomial.Evaluate, but it takes in a single X value, and returns the Y. Is there a function that will take in my entire vector or as an array, that will return a single vector/array of results? Polynomial.Evaluate,但它接受单个 X 值,并返回 Y。是否有一个函数可以接受我的整个向量或作为数组,返回单个向量/结果数组?
You can use Linq's Select.您可以使用 Linq 的 Select。
If you have a collection of X in xCol, and Polynomial.Evaluate
evaluates an X into a Y, you can do the following:如果 xCol 中有 X 的集合,并且Polynomial.Evaluate
将 X 计算为 Y,则可以执行以下操作:
var yCol = xCol.Select(x => Polynomial.Evaluate(x)).
It's effectively a loop, but it looks and acts like a vector function它实际上是一个循环,但它的外观和行为就像一个向量函数
The way it works is that the lamba you specified它的工作方式是您指定的lamba
x => Polynomial.Evaluate(x)
Is applied to each member of xCol
, resulting in an output enumerable collection.应用于xCol
每个成员,从而产生一个输出可枚举集合。
You can read that lambda as "given an x, return Polynomial.Evaluate(x)"你可以把那个 lambda 读作“给定一个 x,返回 Polynomial.Evaluate(x)”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.