Matematické Fórum

Nevíte-li si rady s jakýmkoliv matematickým problémem, toto místo je pro vás jako dělané.

Nástěnka
22. 8. 2021 (L) Přecházíme zpět na doménu forum.matweb.cz!
04.11.2016 (Jel.) Čtete, prosím, před vložení dotazu, děkuji!
23.10.2013 (Jel.) Zkuste před zadáním dotazu použít některý z online-nástrojů, konzultovat použití můžete v sekci CAS.

Nejste přihlášen(a). Přihlásit

#1 18. 06. 2013 21:40

Bugwin
Příspěvky: 34
Škola: 1kspa
Pozice: student
Reputace:   
 

c# Soustavy rovnic

Zdravim,

Dostali jsme za DU, udelat program v C#.
Ma to byt Windows Form App, ktera vypocita Soustavu rovnic o 2 nebo o 3 neznamych, samozrejme cim vic neznamych tim stupen nahoru..

Ale vubec me nenapada jak to udelat, ani jak zacit.

Mohl by mi nekdo poradit, nebo hodit nejakej odkaz kde by bylo podrobne popsane jak vypocitat takovou rovnici? Treba s 1 neznamou.

Dekuji

Offline

 

#2 19. 06. 2013 09:34

rleg
Místo: Ostrava
Příspěvky: 920
Škola: VŠB FMMI (10-16, Ing.)
Reputace:   46 
 

Re: c# Soustavy rovnic

↑ Bugwin:
Ahoj
asi nejjednodušší bude použití Cramerova pravidla - praktický příklad. Pro soustavu 3 rovnic ti bude stačit na výpočet determinantu Sarrusovo pravidlo. Pro determinanty vyšších řádů bys musel zalgoritmizovat LaPlaceův rozvoj.


Radim, tedy jsem.

Dobrá rada je drahá, ta moje je zdarma.

Offline

 

#3 19. 06. 2013 12:16

Bugwin
Příspěvky: 34
Škola: 1kspa
Pozice: student
Reputace:   
 

Re: c# Soustavy rovnic

↑ rleg:

No, problem mam spis v tom jaz napsat kod..
Rovnice umim pocitat za 1 , proto mi dal ten ukol..
Ale jak napsat kod. To me ani nenapada :|

Offline

 

#4 19. 06. 2013 12:59

rleg
Místo: Ostrava
Příspěvky: 920
Škola: VŠB FMMI (10-16, Ing.)
Reputace:   46 
 

Re: c# Soustavy rovnic

↑ Bugwin:
Ty 4 determinanty bych stvořil jako pole (3x3), tam nejhorší bude ty pole naplnit. Buď vymyslíš, jak to zautomatizovat, nebo budeš mít 36 řádků jen zadávání hodnot do polí. A to bolí nejen při psaní kódu (tebe), ale při jeho čtení (kantora).


Radim, tedy jsem.

Dobrá rada je drahá, ta moje je zdarma.

Offline

 

#5 23. 06. 2013 19:23 — Editoval Bugwin (23. 06. 2013 19:23)

Bugwin
Příspěvky: 34
Škola: 1kspa
Pozice: student
Reputace:   
 

Re: c# Soustavy rovnic

↑ rleg:

Tak jsem neco zkousel, a neco jsem udelal. Jako zaklad to snad je. Ted ale nevim jak to udelat dal , aby to spravne spocitalo. Ja si s tema cislama na papire hraju , ale tady nevim jak udelat. Koukal jsem se i na ten odkaz , ale tech cisel je na me moc :D

Prikladam svuj kod.

Code:

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 Soustavy_Rovnic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonVypocitat_Click(object sender, EventArgs e)
        {
            try 
            {
                // Prvni rovnice
                if (textBoxX.Text != "" && !(textBoxX.Text[0] == '+' || textBoxX.Text[0] == '-')) textBoxX.Text = "+" + textBoxX.Text;
                if (textBoxY.Text != "" && !(textBoxY.Text[0] == '+' || textBoxY.Text[0] == '-')) textBoxY.Text = "+" + textBoxY.Text;
                if (textBoxZ.Text != "" && !(textBoxZ.Text[0] == '+' || textBoxZ.Text[0] == '-')) textBoxZ.Text = "+" + textBoxZ.Text;
                if (textBoxNumber.Text != "" && !(textBoxNumber.Text[0] == '+' || textBoxNumber.Text[0] == '-')) textBoxNumber.Text = "+" + textBoxNumber.Text;

                //Druha rovnice
                if (textBoxX1.Text != "" && !(textBoxX1.Text[0] == '+' || textBoxX1.Text[0] == '-')) textBoxX1.Text = "+" + textBoxX1.Text;
                if (textBoxY1.Text != "" && !(textBoxY1.Text[0] == '+' || textBoxY1.Text[0] == '-')) textBoxY1.Text = "+" + textBoxY1.Text;
                if (textBoxZ1.Text != "" && !(textBoxZ1.Text[0] == '+' || textBoxZ1.Text[0] == '-')) textBoxZ1.Text = "+" + textBoxZ1.Text;
                if (textBoxNumber1.Text != "" && !(textBoxNumber1.Text[0] == '+' || textBoxNumber1.Text[0] == '-')) textBoxNumber1.Text = "+" + textBoxNumber1.Text;

                //Treti rovnice
                if (textBoxX2.Text != "" && !(textBoxX2.Text[0] == '+' || textBoxX2.Text[0] == '-')) textBoxX2.Text = "+" + textBoxX2.Text;
                if (textBoxY2.Text != "" && !(textBoxY2.Text[0] == '+' || textBoxY2.Text[0] == '-')) textBoxY2.Text = "+" + textBoxY2.Text;
                if (textBoxZ2.Text != "" && !(textBoxZ2.Text[0] == '+' || textBoxZ2.Text[0] == '-')) textBoxZ2.Text = "+" + textBoxZ2.Text;
                if (textBoxNumber2.Text != "" && !(textBoxNumber2.Text[0] == '+' || textBoxNumber2.Text[0] == '-')) textBoxNumber2.Text = "+" + textBoxNumber2.Text;

                //Prvni rovnice
                String X = textBoxX.Text;
                String Y = textBoxY.Text;
                String Z = textBoxZ.Text;
                String Number = textBoxNumber.Text;

                //Druha rovnice
                String X1 = textBoxX1.Text;
                String Y1 = textBoxY1.Text;
                String Z1 = textBoxZ1.Text;
                String Number1 = textBoxNumber1.Text;

                //Treti rovnice
                String X2 = textBoxX2.Text;
                String Y2 = textBoxY2.Text;
                String Z2 = textBoxZ2.Text;
                String Number2 = textBoxNumber2.Text;

                //Prvni rovnice
                if (X == "") X = "0";
                if (X == "-") X = "-1";
                if (X == "+") X = "1";

                if (Y == "") Y = "0";
                if (Y == "-") Y = "-1";
                if (Y == "+") Y = "1";

                if (Z == "") Z = "0";
                if (Z == "-") Z = "-1";
                if (Z == "+") Z = "1";

                if (Number == "") Number = "0";
                if (Number == "-") Number = "-1";
                if (Number == "+") Number = "1";

                //Druha rovnice
                if (X1 == "") X1 = "0";
                if (X1 == "-") X1 = "-1";
                if (X1 == "+") X1 = "1";

                if (Y1 == "") Y1 = "0";
                if (Y1 == "-") Y1 = "-1";
                if (Y1 == "+") Y1 = "1";

                if (Z1 == "") Z1 = "0";
                if (Z1 == "-") Z1 = "-1";
                if (Z1 == "+") Z1 = "1";

                if (Number1 == "") Number1 = "0";
                if (Number1 == "-") Number1 = "-1";
                if (Number1 == "+") Number1 = "1";

                //Treti rovnice
                if (X2 == "") X2 = "0";
                if (X2 == "-") X2 = "-1";
                if (X2 == "+") X2 = "1";

                if (Y2 == "") Y2 = "0";
                if (Y2 == "-") Y2 = "-1";
                if (Y2 == "+") Y2 = "1";

                if (Z2 == "") Z2 = "0";
                if (Z2 == "-") Z2 = "-1";
                if (Z2 == "+") Z2 = "1";

                if (Number2 == "") Number2 = "0";
                if (Number2 == "-") Number2 = "-1";
                if (Number2 == "+") Number2 = "1";

                //Prvni rovnice
                double x = double.Parse(X);
                double y = double.Parse(Y);
                double z = double.Parse(Z);
                double number = double.Parse(Number);

                //Druha Rovnice
                double x1 = double.Parse(X1);
                double y1 = double.Parse(Y1);
                double z1 = double.Parse(Z1);
                double number1 = double.Parse(Number1);

                //Treti Rovnice
                double x2 = double.Parse(X2);
                double y2 = double.Parse(Y2);
                double z2 = double.Parse(Z2);
                double number2 = double.Parse(Number2);
            }
            catch
            {

                String Vysledek = "Muzete zadat pouze cisla!";
                odpoved.Text = Vysledek.ToString();
            }
        }

    }
}

Jestli by mi to nekdo teda jeste nepomohl vtlouct do hlavy :D

Offline

 

#6 24. 06. 2013 10:29

rleg
Místo: Ostrava
Příspěvky: 920
Škola: VŠB FMMI (10-16, Ing.)
Reputace:   46 
 

Re: c# Soustavy rovnic

↑ Bugwin:
Jestli to správně chápu, tak tohle je kód na zadání a získání koeficientů.

z tohoto už pomocí Sarrusova pravidla poskládáš 4 determinanty pro Cramerovo pravidlo

1.
x*y1*z2+y*z1*x2+x1*y2*z-x2*y1*z-x1*y*z2-x*z1*y2

2. determinant pro X
n*y1*z2+y*z1*n2+n1*y2*z-n2*y1*z-n1*y*z2-n*z1*y2

3. determinant pro Y
x*n1*z2+n*z1*x2+x1*n2*z-x2*n1*z-x1*n*z2-x*z1*n2

4.determinant pro Z
x*y1*n2+y*n1*x2+x1*y2*n-x2*y1*n-x1*y*n2-x*n1*y2

(Snad jsem se nikde nesekl)


Radim, tedy jsem.

Dobrá rada je drahá, ta moje je zdarma.

Offline

 

#7 24. 06. 2013 12:06 — Editoval Bugwin (24. 06. 2013 12:44)

Bugwin
Příspěvky: 34
Škola: 1kspa
Pozice: student
Reputace:   
 

Re: c# Soustavy rovnic

↑ rleg:

Ano, je to jen kod na spravne zadani kooficientu.
Pridal jsem kod pro ziskani determinantu.

A jako vzdy mi nic nejde , vse co zadam se = 0.

Code:

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 Soustavy_Rovnic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonVypocitat_Click(object sender, EventArgs e)
        {
            try 
            {
                // Prvni rovnice
                if (textBoxX.Text != "" && !(textBoxX.Text[0] == '+' || textBoxX.Text[0] == '-')) textBoxX.Text = "+" + textBoxX.Text;
                if (textBoxY.Text != "" && !(textBoxY.Text[0] == '+' || textBoxY.Text[0] == '-')) textBoxY.Text = "+" + textBoxY.Text;
                if (textBoxZ.Text != "" && !(textBoxZ.Text[0] == '+' || textBoxZ.Text[0] == '-')) textBoxZ.Text = "+" + textBoxZ.Text;
                if (textBoxNumber.Text != "" && !(textBoxNumber.Text[0] == '+' || textBoxNumber.Text[0] == '-')) textBoxNumber.Text = "+" + textBoxNumber.Text;

                //Druha rovnice
                if (textBoxX1.Text != "" && !(textBoxX1.Text[0] == '+' || textBoxX1.Text[0] == '-')) textBoxX1.Text = "+" + textBoxX1.Text;
                if (textBoxY1.Text != "" && !(textBoxY1.Text[0] == '+' || textBoxY1.Text[0] == '-')) textBoxY1.Text = "+" + textBoxY1.Text;
                if (textBoxZ1.Text != "" && !(textBoxZ1.Text[0] == '+' || textBoxZ1.Text[0] == '-')) textBoxZ1.Text = "+" + textBoxZ1.Text;
                if (textBoxNumber1.Text != "" && !(textBoxNumber1.Text[0] == '+' || textBoxNumber1.Text[0] == '-')) textBoxNumber1.Text = "+" + textBoxNumber1.Text;

                //Treti rovnice
                if (textBoxX2.Text != "" && !(textBoxX2.Text[0] == '+' || textBoxX2.Text[0] == '-')) textBoxX2.Text = "+" + textBoxX2.Text;
                if (textBoxY2.Text != "" && !(textBoxY2.Text[0] == '+' || textBoxY2.Text[0] == '-')) textBoxY2.Text = "+" + textBoxY2.Text;
                if (textBoxZ2.Text != "" && !(textBoxZ2.Text[0] == '+' || textBoxZ2.Text[0] == '-')) textBoxZ2.Text = "+" + textBoxZ2.Text;
                if (textBoxNumber2.Text != "" && !(textBoxNumber2.Text[0] == '+' || textBoxNumber2.Text[0] == '-')) textBoxNumber2.Text = "+" + textBoxNumber2.Text;

                //Prvni rovnice
                String X = textBoxX.Text;
                String Y = textBoxY.Text;
                String Z = textBoxZ.Text;
                String Number = textBoxNumber.Text;

                //Druha rovnice
                String X1 = textBoxX1.Text;
                String Y1 = textBoxY1.Text;
                String Z1 = textBoxZ1.Text;
                String Number1 = textBoxNumber1.Text;

                //Treti rovnice
                String X2 = textBoxX2.Text;
                String Y2 = textBoxY2.Text;
                String Z2 = textBoxZ2.Text;
                String Number2 = textBoxNumber2.Text;

                //Prvni rovnice
                if (X == "") X = "0";
                if (X == "-") X = "-1";
                if (X == "+") X = "1";

                if (Y == "") Y = "0";
                if (Y == "-") Y = "-1";
                if (Y == "+") Y = "1";

                if (Z == "") Z = "0";
                if (Z == "-") Z = "-1";
                if (Z == "+") Z = "1";

                if (Number == "") Number = "0";
                if (Number == "-") Number = "-1";
                if (Number == "+") Number = "1";

                //Druha rovnice
                if (X1 == "") X1 = "0";
                if (X1 == "-") X1 = "-1";
                if (X1 == "+") X1 = "1";

                if (Y1 == "") Y1 = "0";
                if (Y1 == "-") Y1 = "-1";
                if (Y1 == "+") Y1 = "1";

                if (Z1 == "") Z1 = "0";
                if (Z1 == "-") Z1 = "-1";
                if (Z1 == "+") Z1 = "1";

                if (Number1 == "") Number1 = "0";
                if (Number1 == "-") Number1 = "-1";
                if (Number1 == "+") Number1 = "1";

                //Treti rovnice
                if (X2 == "") X2 = "0";
                if (X2 == "-") X2 = "-1";
                if (X2 == "+") X2 = "1";

                if (Y2 == "") Y2 = "0";
                if (Y2 == "-") Y2 = "-1";
                if (Y2 == "+") Y2 = "1";

                if (Z2 == "") Z2 = "0";
                if (Z2 == "-") Z2 = "-1";
                if (Z2 == "+") Z2 = "1";

                if (Number2 == "") Number2 = "0";
                if (Number2 == "-") Number2 = "-1";
                if (Number2 == "+") Number2 = "1";

                //Prvni rovnice
                double x = double.Parse(X);
                double y = double.Parse(Y);
                double z = double.Parse(Z);
                double number = double.Parse(Number);

                //Druha Rovnice
                double x1 = double.Parse(X1);
                double y1 = double.Parse(Y1);
                double z1 = double.Parse(Z1);
                double number1 = double.Parse(Number1);

                //Treti Rovnice
                double x2 = double.Parse(X2);
                double y2 = double.Parse(Y2);
                double z2 = double.Parse(Z2);
                double number2 = double.Parse(Number2);

                //Determinant
                Double DN = x * y1 * z2 + y * z1 * x2 + x1 * y2 * z - x2 * y1 * z - x1 * y * z2 - x * z1 * y2; 

                //Determinant X
                Double DX = number * y1 * z2 + y * z1 * number2 + number1 * y2 * z - number2 * y1 * z - number1 * y * z2 - number * z1 * y2;

                //Determinant Y
                Double DY = x * number1 * z2 + number * z1 * x2 + x1 * number2 * z - x2 * number1 * z - x1 * number * z2 - x * z1 * number2;

                //Determinant Z
                Double DZ = x * y1 * number2 + y * number1 * x2 + x1 * y2 * number - x2 * y1 * number - x1 * y * number2 - x * number1 * y2;

                if(DN == 0)
                {
                    String Vysledek = "Soustava ma nekonecne mnoho reseni";
                    chyba.Text = Vysledek.ToString();
                }
                else if (DN > 0)
                {
                    Double Vysledek = (DX/DN);
                    odpovedX.Text = Vysledek.ToString();

                    Double Vysledek1 = (DY/DN);
                    odpovedY.Text = Vysledek1.ToString();

                    Double Vysledek2 = (DZ/DN);
                    odpovedZ.Text = Vysledek2.ToString();
                }
                else if (DN > 0)
                {
                    Double Vysledek = (DX/DN);
                    odpovedX.Text = Vysledek.ToString();

                    Double Vysledek1 = (DY/DN);
                    odpovedY.Text = Vysledek1.ToString();

                    Double Vysledek2 = (DZ/DN);
                    odpovedZ.Text = Vysledek2.ToString();
                }

            }
            catch
            {

                String Vysledek = "Muzete zadat pouze cisla!";
                odpovedX.Text = Vysledek.ToString();
            }
        }

    }
}

EDIT//: Ja jsem blb.. Ja jsem v "else if (DN > 0)" a "else if (DN > 0)" dal stejny znaminko >. :|
Ted to funguje. Dekuji moc

Offline

 

Zápatí

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson