public void Calculate() { float xp = (float)dane.GetXp(); float xk = (float)dane.GetXk(); float h = (float)dane.GetN(); int n = (int)((xk - xp) / h); float ybuf = dane.getPoint(0).Y; float xbuf = dane.getPoint(0).X; for (int i = 0; i < n; i++) { float x1 = xbuf + h; float k1 = h * (float)dane.getFunctionInPointXY(xbuf, ybuf); float k2 = h * (float)dane.getFunctionInPointXY(xbuf + h / 2, k1 / 2 + ybuf); float k3 = h * (float)dane.getFunctionInPointXY(xbuf + h / 2, k2 / 2 + ybuf); float k4 = h * (float)dane.getFunctionInPointXY(xbuf + h, k3 + ybuf); float y1 = ybuf + (k1 + 2 * k2 + 2 * k3 + k4) / 6; PointF bufor = new PointF(x1, y1); dane.AddPoint(bufor); // Console.WriteLine(x1 + ": " + y1); xbuf = x1; ybuf = y1; } dane.SetDrawable(); }
public void Calculate() { float xp = (float)dane.GetXp(); float xk = (float)dane.GetXk(); float h = (float)dane.GetN(); int n = (int)((xk - xp) / h); float ybuf = dane.getPoint(0).Y; float xbuf = dane.getPoint(0).X; for (int i = 0; i < n; i++) { float yn = ybuf + h / 2 * ((float)dane.getFunctionInPointXY(xbuf, ybuf) + (float)dane.getFunctionInPointXY(xbuf + h, ybuf + h * (float)dane.getFunctionInPointXY(xbuf, ybuf))); float xn = xbuf + h; PointF bufor = new PointF(xn, yn); dane.AddPoint(bufor); // Console.WriteLine(xn+": "+ yn ); xbuf = xn; ybuf = yn; } dane.SetDrawable(); }
public void Calculate() { float xp = (float)dane.GetXp(); float xk = (float)dane.GetXk(); float h = (float)dane.GetN(); int n = (int)((xk - xp) / h); int iterator = 0; float y_temp = dane.getPoint(0).Y; for (float i = xp; i < xk; i += h) { float y1 = y_temp + h * (float)dane.getFunctionInPointXY(i, y_temp); PointF bufor = new PointF(i + h, y1); dane.AddPoint(bufor); //Console.WriteLine((i + h).ToString()+" "+y1); y_temp = y1; iterator++; } dane.SetDrawable(); }
private void loadFile_DROP(object sender, DragEventArgs e) { //if (Datas.Count() > 0) //Datas.Clear(); try { string[] a = (string[])e.Data.GetData(DataFormats.FileDrop, false); if (a != null) { for (int i = 0; i < a.Length; i++) { FileStream fs = new FileStream(a.GetValue(i).ToString(), FileMode.Open, FileAccess.Read); try { Data DataBufor = new Data(); DataBufor.SetFileName(Path.GetFileName(a.GetValue(i).ToString())); StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) { String bufor = sr.ReadLine(); if (String.IsNullOrEmpty(bufor)) { continue; } bufor = (bufor.Trim(' ')).ToLower(); String[] pociete = bufor.Split('='); pociete[0] = pociete[0].TrimEnd(' '); pociete[1] = pociete[1].Trim(' '); if (pociete[0].Equals("f(x,y)") || pociete[0].Equals("f(x)") || pociete[0].Equals("f'(x)")) { //Pobieranie funkcji f(x,y), f(x), f'(x) String BuforujText = pociete[1]; Dictionary <int, double> temporaryFunctionX = new Dictionary <int, double>(); Dictionary <int, double> temporaryFunctionY = new Dictionary <int, double>(); int maxRatioX = -1; int maxRatioY = -1; while (!String.IsNullOrEmpty(BuforujText)) { BuforujText = BuforujText.Trim(' '); int positionOfMinus = TryFindMinus(BuforujText); int positionOfPlus = TryFindSth(BuforujText, '+'); int positionOfX = TryFindSth(BuforujText, 'x'); int positionOfY = TryFindSth(BuforujText, 'y'); bool subtract = false; if (positionOfMinus == 0 || positionOfPlus == 0) { BuforujText = BuforujText.Remove(0, 1); if (positionOfMinus == 0) { subtract = true; } positionOfMinus = TryFindMinus(BuforujText); positionOfPlus = TryFindSth(BuforujText, '+'); } String toCut = BuforujText.Substring(0, (positionOfMinus < positionOfPlus) ? positionOfMinus : positionOfPlus); BuforujText = BuforujText.Remove(0, (positionOfMinus < positionOfPlus) ? positionOfMinus : positionOfPlus); String[] toOperate; if (positionOfX <= positionOfY) { toOperate = toCut.Split('x'); } else { toOperate = toCut.Split('y'); } if (toOperate.Length > 1 && !String.IsNullOrEmpty(toOperate[1])) { toOperate[1] = toOperate[1].Remove(toOperate[1].IndexOf('^'), 1); } int temp = (toOperate.Length > 1) ? (String.IsNullOrEmpty(toOperate[1]))?1:int.Parse(toOperate[1].Trim(' ')) : 0; if (temp > maxRatioX && positionOfX < positionOfY) { maxRatioX = temp; } else if (temp > maxRatioY && positionOfX > positionOfY) { maxRatioY = temp; } if (String.IsNullOrEmpty(toOperate[0])) { if (positionOfX <= positionOfY) { if (!temporaryFunctionX.ContainsKey(temp)) { temporaryFunctionX.Add(temp, (subtract) ? -1 : 1); } } else { if (!temporaryFunctionY.ContainsKey(temp)) { temporaryFunctionY.Add(temp, (subtract) ? -1 : 1); } } } else { if (positionOfX <= positionOfY) { if (!temporaryFunctionX.ContainsKey(temp)) { temporaryFunctionX.Add(temp, double.Parse((subtract) ? "-" + toOperate[0].Trim(' ') : toOperate[0].Trim(' '))); } else { temporaryFunctionX[temp] += double.Parse((subtract) ? "-" + toOperate[0].Trim(' ') : toOperate[0].Trim(' ')); } } else { if (!temporaryFunctionY.ContainsKey(temp)) { temporaryFunctionY.Add(temp, double.Parse((subtract) ? "-" + toOperate[0].Trim(' ') : toOperate[0].Trim(' '))); } else { temporaryFunctionY[temp] += double.Parse((subtract) ? "-" + toOperate[0].Trim(' ') : toOperate[0].Trim(' ')); } } } } if (!pociete[0].Equals("f'(x)")) { DataBufor.AddFunctionX(temporaryFunctionX, maxRatioX); DataBufor.AddFunctionY(temporaryFunctionY, maxRatioY); } else { DataBufor.AddDerivative(temporaryFunctionX, maxRatioX); } } else if (pociete[1].Equals("?")) { //Pobieranie wartości szukanej pociete[0] = (pociete[0].Remove(pociete[0].IndexOf(")"), 1)).Remove(pociete[0].IndexOf("f("), 2); DataBufor.SetToFind(Double.Parse(pociete[0].Trim(' '))); ; } else if (pociete[0].Equals("xk")) { //Pobranie wartości Xk DataBufor.SetXk(Double.Parse(pociete[1].Trim(' '))); } else if (pociete[0].Equals("xp")) { DataBufor.SetXp(Double.Parse(pociete[1].Trim(' '))); //Pobranie wartości Xp } else if (pociete[0].Equals("n")) { DataBufor.SetN(Double.Parse(pociete[1].Trim(' '))); //Pobranie wartości n } else if (pociete[0].Equals("prec")) { DataBufor.SetPrecision(Double.Parse(pociete[1].Trim(' '))); //Pobranie wartości Dokładności } else { //Pobranie punktu pociete[0] = (pociete[0].Remove(pociete[0].IndexOf(")"), 1)).Remove(pociete[0].IndexOf("f("), 2); DataBufor.AddPoint(new PointF(float.Parse(pociete[0].Trim(' ')), float.Parse(pociete[1].Trim(' ')))); } } Datas.Add(DataBufor); sr.Close(); } catch (Exception ex) { MessageBox.Show("Wykryto błąd składni pliku! Sprawdz czy używasz przecinków a nie kropek!"); Console.WriteLine(ex.ToString()); } fs.Close(); } } } catch (Exception ex) { Console.WriteLine("Error in DragDrop function: " + ex.Message); } }