Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp4
- {
- public partial class Form1 : Form
- {
- double x3, x2, x1, x, ex, a, b, E, ww;
- public Form1()
- {
- InitializeComponent();
- }
- private void x3TB_TextChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- x3 = double.Parse(x3TB.Text);
- x2 = double.Parse(x2TB.Text);
- x1 = double.Parse(x1TB.Text);
- ex = double.Parse(exTB.Text);
- a = double.Parse(aTB.Text);
- b = double.Parse(bTB.Text);
- E = double.Parse(ETB.Text);
- ww = double.Parse(wwTB.Text);
- if (policz(a) < 0 && policz(b) > 0 && drugaPoch(b) > 0)
- {
- przyblizenie(b,a);
- }
- else if (policz(a) > 0 && policz(b) < 0 && drugaPoch(a) > 0)
- {
- przyblizenie(a,b);
- }
- else if (policz(a) > 0 && policz(b) < 0 && drugaPoch(b) < 0)
- {
- przyblizenie(b,a);
- }
- else if (policz(a) < 0 && policz(b) > 0 && drugaPoch(a) < 0)
- {
- przyblizenie(a,b);
- }
- else
- {
- xTB.Text = "Brak rozwiązań";
- }
- }
- private double policz(double iks)
- {
- return x3 * Math.Pow(iks, 3) + x2 * Math.Pow(iks, 2) + x1 * iks + ex * Math.Exp(iks) + ww;
- }
- private double pierwPoch(double iks)
- {
- return 3 * x3 * Math.Pow(iks, 2) + 2 * x2 * Math.Pow(iks, 1) + x1 * 1 + ex * Math.Exp(iks);
- }
- private double drugaPoch(double x)
- {
- return 3 * 2 * x3 * x + 2 * x2 + Math.Exp(x)*ex;
- }
- private void przyblizenie(double a,double b)
- {
- double wynik,wynik2,wkon;
- do
- {
- a = a - (policz(a) / (policz(b) - policz(a))) * (b - a);
- } while (!(Math.Abs(policz(a)) < E));// || Math.Abs(wynik2 - wkon) < E);
- xTB.Text = a.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement