public void Plot(float?newMinX = null, float?newMaxX = null, float?newMinY = null, float?newMaxY = null) { if (newMinX != null) { minX = (float)newMinX; } if (newMaxX != null) { maxX = (float)newMaxX * 1.02f; } if (newMinY != null) { minY = (float)newMinY; } if (newMaxY != null) { maxY = (float)newMaxY; } //Debug.Log("Range: " + minX + " to " + maxX); float intervalX = (maxX - minX) / pointNum; //Debug.Log("Best Fit Line Interval: " + intervalX); string yExpression = ExpressionForY(rounded: false); // exception for y = infinity. if (yExpression == "") { dataSeries.seriesName = "\ty = undefined"; return; } // get data series legend to show r, to save space dataSeries.seriesName = "\tr = " + PearsonsPMCC(rounded: true); lineSeries.seriesName = "\ty = " + ExpressionForY(rounded: true); lineSeries.pointValues.Clear(); string formattedEquationStr = EnsureDelimiterAroundOperatorsAndParentheses(yExpression); List <string> rpnString = WMG_Util.ShuntingYardAlgorithm(formattedEquationStr); for (float i = minX; i <= (maxX + Mathf.Epsilon); i += intervalX) { i = Mathf.Round(i * decimalsMultiplier) / decimalsMultiplier; Vector2 expResult = WMG_Util.ExpressionEvaluator(rpnString, i); if (!float.IsNaN(expResult.y) && (minY <= expResult.y) && (expResult.y <= maxY)) { lineSeries.pointValues.Add(expResult); } } //Debug.Log("y = " + ExpressionForY(rounded:true)); }
public void OnPlot() { series.seriesName = equationStr; series.pointValues.Clear(); string formattedEquationStr = ensureDelimiterAroundOperatorsAndParentheses(equationStr); List <string> rpnString = WMG_Util.ShuntingYardAlgorithm(formattedEquationStr); for (float i = minX; i <= (maxX + Mathf.Epsilon); i += intervalX) { i = Mathf.Round(i * decimalsMultiplier) / decimalsMultiplier; Vector2 expResult = WMG_Util.ExpressionEvaluator(rpnString, i); if (!float.IsNaN(expResult.y)) { series.pointValues.Add(expResult); } } }