# Answer to Question #15625 in C++ for adam

Question #15625

Solve the coupled differential equations using Rutta-Kutta method.

dx/dt=(x/tc)*((y/Nt)-1)

dy/dt=(-2x/tc)(y/Nt)

Where

initial y = 10e19

initial x =1

Nt = 10e18

nr = 1.5

D = 0.1

c = 3*10e8

tc = 2D/(0.1(c/nr))

dx/dt=(x/tc)*((y/Nt)-1)

dy/dt=(-2x/tc)(y/Nt)

Where

initial y = 10e19

initial x =1

Nt = 10e18

nr = 1.5

D = 0.1

c = 3*10e8

tc = 2D/(0.1(c/nr))

Expert's answer

#include<iostream>

#include<iomanip>

#include <math.h>

using namespace std;

double f(double x,double y)

{return (y-(pow(10.0,18))/2*y);}

int main()

{double h=0.1;

double y[11],x[11];

int k;

k=pow(10.0,19);

y[0]=k;

for(int i=0; i<11;i++){x[i]=i*h;}

for(int i=0; i<11;i++)

{y[i+1]=y[i]+h*( f(x[i],y[i]) + 2*f((x[i]+h/2),(y[i]+f(x[i],y[i])/2)) + 2*f((x[i]+h/2),(y[i]+f((x[i]+h/2),(y[i]+f(x[i],y[i])/2))/2)) +

f((x[i]+h),(y[i]+f((x[i]+h/2),(y[i]+f((x[i]+h/2),(y[i]+f(x[i],y[i])/2))/2)))))/6;}

for(int i=0; i<11;i++){cout<<setw(50)<<x[i]<<setw(50)<<y[i]<<endl;}

double l=0;

cin>>l;

return 0;}

#include<iomanip>

#include <math.h>

using namespace std;

double f(double x,double y)

{return (y-(pow(10.0,18))/2*y);}

int main()

{double h=0.1;

double y[11],x[11];

int k;

k=pow(10.0,19);

y[0]=k;

for(int i=0; i<11;i++){x[i]=i*h;}

for(int i=0; i<11;i++)

{y[i+1]=y[i]+h*( f(x[i],y[i]) + 2*f((x[i]+h/2),(y[i]+f(x[i],y[i])/2)) + 2*f((x[i]+h/2),(y[i]+f((x[i]+h/2),(y[i]+f(x[i],y[i])/2))/2)) +

f((x[i]+h),(y[i]+f((x[i]+h/2),(y[i]+f((x[i]+h/2),(y[i]+f(x[i],y[i])/2))/2)))))/6;}

for(int i=0; i<11;i++){cout<<setw(50)<<x[i]<<setw(50)<<y[i]<<endl;}

double l=0;

cin>>l;

return 0;}

## Comments

## Leave a comment