Puedes seguirnos en

BUSCADOR

Engineering

Solve Runge-Kutta Second Order using a Program

The fundamental method in obtaining the solution of differential equation is extrapolation. And Runge-Kutta method is the most accurate.
So in this post we will learn how to solve Runge-Kutta Second order method using a C++ Program.

The following video demonstrates how:

VIDEO TUTORIAL

 

Anuncio publicitario

CODE


 #include <iostream>
 #include <stdlib.h>
 #include <cstdlib>
 
 using namespace std;
 
 int repeat()
 {
 int ch;
 cout<<"\n\nWANT TO TRY AGAIN?";
 cout<<"\tTO CONTINUE PRESS 1\n PRESS ANY OTHER KEY TO EXIT";
cin>>ch;
 if(ch==1)
 {
 return 1;
}
 else
 {
 return 0;
 }
}
int main()
 {
 int option;
 float x,y,h;
 float k1,k2,k=0;
 label:
 cout<<"PLEASE ENTER THE CORRESPONDING VALUES: ";
 cout<<endl<<"X= ";
 cin>>x;
 cout<<endl<<"Y= ";
 cin>>y;
cout<<endl<<"H= ";
 cin>>h;
 system("cls");
 cout<<"\nGIVEN DATA: ";
 cout<<"\nX= "<<x<<"\tY= "<<y<<"\tH= "<<h;
cout<<"\nForumala for Calculations: "<<endl;
 cout<<endl<<"FORMULA OF K1= hf[x0,y0]";
 cout<<endl<<"FORMULA OF K2= hf[x0+h,y0+k1]";
 cout<<endl;
 cout<<"\n*******CHOSE FORMAT OF THE FUNCTION*******";
 cout<<"\t\n1. f(x)= x + y";
 cout<<"\t\n2. f(x)= x * y";
 cout<<"\t\n3. f(x)= x2 + xy";
 cout<<"\nEnter Option: ";
 cin>>option;
switch(option)
 {
 case 1:
 k1=(float) h*(x+y); // KI CALCULATED
 cout<<endl<<"K1= "<<k1;
k2=h*(x+h+y+k1);
 cout<<endl<<"K2= "<<k2;
k=(k1+k2)/2;
 cout<<endl<<"AVERAGE K= "<<k;
if(repeat()==1)
 {
 system("cls");
 goto label;
 }
 else
 {
 exit(0);
 }
 break;
case 2:
 k1=(float) h*(x*y); // KI CALCULATED
 cout<<endl<<"K1= "<<k1;
 k2=h*((x+h)*(y+k1));
 cout<<endl<<"K2= "<<k2;
 k=(k1+k2)/2;
 cout<<endl<<"AVERAGE K= "<<k;
if(repeat()==1)
 {
 system("cls");
 goto label;
 }
 else
 {
 exit(0);
 }
break;
case 3:
k1=(float) h*((x*x)+(x*y)); // KI CALCULATED
 cout<<endl<<"K1= "<<k1;
 k2=x=(x+h);
 k2=h*((x*x)+((y+k1)*x));
cout<<endl<<"K2= "<<k2;
 k=(k1+k2)/2;
 cout<<endl<<"AVERAGE K= "<<k;
if(repeat()==1)
 {
 system("cls");
 goto label;
 }
 else
 {
 exit(0);
 }
 break;
default:
 cout<<endl<<"INCORRECT OPTION";
}//end switch
 }

Escrito por

Administrador de ENGGDRCAOS. Canal dedicado especialmente a la formación del estudiante que aspira a ser ingeniero. Todos los videos son Ingles. Apasionado del universo Apple, estudiante de Ingeniería y Gamer por vocación.

Publicidad

ARTÍCULOS RELACIONADOS

Engineering

Function prototyping is one of the key improvements added to the C++ functions. When a function call is encountered, the compiler checks the function...

Engineering

If we want two computers to communicate over a network, then the protocols on each layer of OSI model in the sending computer should...

Engineering

When virtual functions are created for implementing late binding, there are some basic rules that satisfy the compiler requirements: The virtual function must be...

Engineering

In assembly language programs, small sequence of codes of the same pattern are repeated frequently at different places which perform the same operation on...