This commit is contained in:
2020-08-01 14:02:23 +03:00
parent a43b7f54ce
commit 918270d930
3 changed files with 148 additions and 8 deletions

View File

@@ -97,6 +97,28 @@ namespace MatrixExtensions
new ArgumentInfo(ArgumentSections.ColumnVector), new ArgumentInfo(ArgumentSections.RealNumber),
new ArgumentInfo(ArgumentSections.RealNumber)),
new TermInfo("matrixRInsert", TermType.Function,
"Вставка нулевой строки в матрицу ('матрица') по указанному индексу ('число').",
FunctionSections.MatricesAndVectors, true,
new ArgumentInfo(ArgumentSections.Matrix), new ArgumentInfo(ArgumentSections.RealNumber)),
new TermInfo("matrixRInsert", TermType.Function,
"Вставка строки в матрицу ('1:матрица') по указанному индексу ('число') из вектора ('3:матрица').",
FunctionSections.MatricesAndVectors, true,
new ArgumentInfo(ArgumentSections.Matrix), new ArgumentInfo(ArgumentSections.RealNumber),
new ArgumentInfo(ArgumentSections.Matrix)),
new TermInfo("matrixCInsert", TermType.Function,
"Вставка нулевого столбца в матрицу ('матрица') по указанному индексу ('число').",
FunctionSections.MatricesAndVectors, true,
new ArgumentInfo(ArgumentSections.Matrix), new ArgumentInfo(ArgumentSections.RealNumber)),
new TermInfo("matrixCInsert", TermType.Function,
"Вставка столбца в матрицу ('1:матрица') по указанному индексу ('число') из вектора ('3:матрица').",
FunctionSections.MatricesAndVectors, true,
new ArgumentInfo(ArgumentSections.Matrix), new ArgumentInfo(ArgumentSections.RealNumber),
new ArgumentInfo(ArgumentSections.Matrix)),
};
}
@@ -242,8 +264,7 @@ namespace MatrixExtensions
m[0, 0] = tmp1;
}
List<Term> answer = new List<Term>(m.ToTerms());
result = Entry.Create(answer.ToArray());
result = Entry.Create(m.ToTerms());
return true;
}
@@ -383,7 +404,6 @@ namespace MatrixExtensions
return true;
}
if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "listInsert")
{
Entry arg1 = Computation.Preprocessing(value.Items[0], context);
@@ -460,6 +480,76 @@ namespace MatrixExtensions
return true;
}
if (value.Type == TermType.Function && value.ArgsCount == 2 && value.Text == "matrixRInsert")
{
Entry arg1 = Computation.Preprocessing(value.Items[0], context);
Entry arg2 = Computation.Preprocessing(value.Items[1], context);
TNumber tmp1 = Computation.NumericCalculation(arg1, context);
TNumber tmp2 = Computation.NumericCalculation(arg2, context);
MatrixL<TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
matrixL.InsertRow(tmp2.ToInt32()-1);
TMatrix m = Utilites.MatrixLToTMatrix(matrixL);
//MatrixL<TNumber> vectorL = Utilites.TMatrixToMatrixL(tmp2);
result = Entry.Create(m.ToTerms());
return true;
}
if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "matrixRInsert")
{
Entry arg1 = Computation.Preprocessing(value.Items[0], context);
Entry arg2 = Computation.Preprocessing(value.Items[1], context);
Entry arg3 = Computation.Preprocessing(value.Items[2], context);
TNumber tmp1 = Computation.NumericCalculation(arg1, context);
TNumber tmp2 = Computation.NumericCalculation(arg2, context);
TNumber tmp3 = Computation.NumericCalculation(arg3, context);
MatrixL<TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
List<TNumber> vectorL = Utilites.TMatrixToMatrixL(tmp3).ToList();
matrixL.InsertRow(tmp2.ToInt32() - 1, vectorL);
TMatrix m = Utilites.MatrixLToTMatrix(matrixL);
//MatrixL<TNumber> vectorL = Utilites.TMatrixToMatrixL(tmp2);
result = Entry.Create(m.ToTerms());
return true;
}
if (value.Type == TermType.Function && value.ArgsCount == 2 && value.Text == "matrixCInsert")
{
Entry arg1 = Computation.Preprocessing(value.Items[0], context);
Entry arg2 = Computation.Preprocessing(value.Items[1], context);
TNumber tmp1 = Computation.NumericCalculation(arg1, context);
TNumber tmp2 = Computation.NumericCalculation(arg2, context);
MatrixL<TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
matrixL.InsertCol(tmp2.ToInt32()-1);
TMatrix m = Utilites.MatrixLToTMatrix(matrixL);
//MatrixL<TNumber> vectorL = Utilites.TMatrixToMatrixL(tmp2);
result = Entry.Create(m.ToTerms());
return true;
}
if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "matrixCInsert")
{
Entry arg1 = Computation.Preprocessing(value.Items[0], context);
Entry arg2 = Computation.Preprocessing(value.Items[1], context);
Entry arg3 = Computation.Preprocessing(value.Items[2], context);
TNumber tmp1 = Computation.NumericCalculation(arg1, context);
TNumber tmp2 = Computation.NumericCalculation(arg2, context);
TNumber tmp3 = Computation.NumericCalculation(arg3, context);
MatrixL<TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
List<TNumber> vectorL = Utilites.TMatrixToMatrixL(tmp3).ToList();
matrixL.InsertCol(tmp2.ToInt32() - 1, vectorL);
TMatrix m = Utilites.MatrixLToTMatrix(matrixL);
//MatrixL<TNumber> vectorL = Utilites.TMatrixToMatrixL(tmp2);
result = Entry.Create(m.ToTerms());
return true;
}
result = null;
return false;
}

View File

@@ -161,13 +161,17 @@ namespace MatrixExtensions
int n = r;
if (col.Count < r) n = col.Count;
foreach (List<T> item in src)
for (int i = 0; i < n; i++)
{
for (int i = 0; i < n; i++) item[i] = col[i];
if (col.Count < r)
for (int j = 0; j < r; j++)
{
for (int i = n; i < r; i++) item[i] = init;
//src[j].Insert(idxC, col[i]);
src[j][idxC] = col[i];
if (col.Count < r)
{
//src[j].Insert(idxC, init);
src[j][idxC] = col[i];
}
}
}
}
@@ -192,5 +196,19 @@ namespace MatrixExtensions
}
else throw new ArgumentException("Матрица пустая либо не верно указан индекс столбца для удаления.");
}
public List<T> ToList()
{
List<T> res = new List<T>(r * c);
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
res.Add(src[i][j]);
}
}
return res;
}
}
}

View File

@@ -51,5 +51,37 @@ namespace MatrixExtensions
string source = prime.ToString();
return Convert.ToInt32(source);
}
internal static MatrixL<TNumber> TMatrixToMatrixL(TNumber src)
{
if (src.obj.Type != BaseEntryType.Matrix) return null;
int r = src.Rows().ToInt32();
int c = src.Cols().ToInt32();
MatrixL<TNumber> res = new MatrixL<TNumber>(r, c, new TNumber(0,1));
TMatrix matrix = (TMatrix)src.obj;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
res[i, j] = matrix[i, j];
}
}
return res;
}
internal static TMatrix MatrixLToTMatrix(MatrixL<TNumber> src)
{
TMatrix res = new TMatrix(new TNumber[src.R, src.C]);
for (int i = 0; i < src.R; i++)
{
for (int j = 0; j < src.C; j++)
{
res[i, j] = src[i, j];
}
}
return res;
}
}
}