c++ układ równań

marek12
Użytkownik
Użytkownik
Posty: 696
Rejestracja: 5 lut 2008, o 15:38
Płeć: Mężczyzna
Lokalizacja: marki
Podziękował: 165 razy
Pomógł: 20 razy

c++ układ równań

Post autor: marek12 »

mam taki kod, chciałbym żeby rozwiązywał ten układ ale nie wiem co jest nie tak, moze cos przekombinoawałem?
\(\displaystyle{ dx/dt=0.1x-0.01xy}\)
\(\displaystyle{ dy/dt=0.001xy-0.05y}\)

Kod: Zaznacz cały

#include <iostream>
#include <iomanip>
using namespace std;


#define X0 15
#define Y0 50
#define H  0.01
#define N  10

double f1(double x, double y);
double f(double x, double y);
double runge(double x, double y);
double runge1(double x, double y);

int main(double x, double y)
{
      
        cout<<"     "
                <<setw(12)<<"x"<<setw(12)<<"	y"
                <<"
"
                <<"	------------------------------"
                <<"
";
       
        y=Y0;
        x=X0;
        for(int i=0;i<=200;i++)
        {
                y=runge(x,y);
                x=runge1(x,y);
             
                cout<<left<<setw(0)<<i<<"|"
                        <<setprecision(4)<<left<<setw(8)<<"	"<<x
                        <<setprecision(4)<<left<<setw(8)<<"	"<<y;
                cout<<"

";
        }
        cout<<"

";
        system("pause");
        return 0;
}

double runge(double x, double y)
{
    double K1    = (H * f(x,y));
    double K2    = (H * f((x + 1 / 2 * H), (y + 1 / 2 * K1)));
    double K3    = (H * f((x + 1 / 2 * H), (y + 1 / 2 * K2)));
    double K4    = (H * f((x + H), (y + K3)));
        double runge = (y + ((K1 + 2 * K2 + 2 * K3 + K4)/6));
        return runge;
}

double f(double x, double y)
{
      
        double f = 0.001*x*y-0.05*y;
        return f;
}
double runge1(double x, double y)
{
    double K1    = (H * f(x,y));
    double K2    = (H * f((x + 1 / 2 * K1),(y + 1 / 2 * H)));
    double K3    = (H * f((x + 1 / 2 * K2),(y + 1 / 2 * H)));
    double K4    = (H * f((x + K3),(y + H)));
        double runge1 = (x + ((K1 + 2 * K2 + 2 * K3 + K4)/6));
        return runge1;
}

double f1(double x, double y)
{
       
         double f1 = 0.1*x-0.01*x*y;
        return f1;
}






ODPOWIEDZ