public Matrix ConvertToMatrix() { string tempExpress = strExpress.Substring(1, strExpress.Length - 2); string[] rows = tempExpress.Split(';'); string[] firstRow = rows[0].Trim().Split(new char[] { ' ', ',' }); int col = 0; for (int i = 0; i < firstRow.Length; i++) { if (string.IsNullOrEmpty(firstRow[i])) { } else { col++; } } int row = rows.Length; double[,] data = new double[row, col]; try { for (int i = 0; i < row; i++) { string[] singlerow = rows[i].Trim().Split(new char[] { ' ', ',' }); int column = 0; for (int j = 0; column < col; j++) { if (j < singlerow.Length) { if (string.IsNullOrEmpty(singlerow[j])) { continue; } string str = new UExpData(singlerow[j].Trim()).GetValueEx(); data[i, column] = double.Parse(str); } else { data[i, column] = 0; } column++; } } } catch (ExpError e) { throw new AssignedError(e.Message + "\nAssignmentError::矩阵转换出错\n"); } Matrix matrix = new Matrix(data); cd = matrix; return(matrix); }
public BlockData ConverToBlock() { function.FuncString funstring = new function.FuncString(strExpress); int leftBracket = funstring.FindOp(0, '('); int rightBracket = funstring.FindOp(0, ')'); int commaSymbol = funstring.FindOp(0, ','); string[] ab = strExpress.Split(','); double a = 0; double b = 0; try { string strA = new UExpData(ab[0].Substring(1)).GetValueEx(); string strB = new UExpData(ab[1].Substring(0, ab[1].Length - 1)).GetValueEx(); a = double.Parse(strA); b = double.Parse(strB); } catch (ExpError e) { throw new AssignedError(e.Message + "\nAssignmentError::区间转换出错" + "\n"); } BlockData bd = new BlockData(a, b); bool left; bool right; if (leftBracket != -1 && leftBracket < commaSymbol) { left = false; } else { left = true; } if (rightBracket != -1 && rightBracket > commaSymbol) { right = false; } else { right = true; } bd.SetBlockBounderAvailable(left, right); cd = bd; return(bd); }