0% found this document useful (0 votes)
55 views

#Include #Include #Define Float Float Float Return

The document discusses the Runge-Kutta method for solving differential equations numerically. It presents code for implementing the second-order Runge-Kutta method to solve the differential equation dy/dx = x*y. The code takes user input for the bounds of x and the initial y value, then iterates to calculate successive y values within the bounds. The output displays the calculated x and y value pairs. A second example implements the fourth-order Runge-Kutta method to solve the equation dy/dx = 1 + y^2.

Uploaded by

nikimegs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

#Include #Include #Define Float Float Float Return

The document discusses the Runge-Kutta method for solving differential equations numerically. It presents code for implementing the second-order Runge-Kutta method to solve the differential equation dy/dx = x*y. The code takes user input for the bounds of x and the initial y value, then iterates to calculate successive y values within the bounds. The output displays the calculated x and y value pairs. A second example implements the fourth-order Runge-Kutta method to solve the equation dy/dx = 1 + y^2.

Uploaded by

nikimegs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Range kutta method

#include<stdio.h>
#include<conio.h>
#define MAX 20

float equation(float x,float y)
{
return(x*y);
}

void main()
{
FILE *fp;
int i=1,count=1;
float lower,upper,y1,h,xvalue[MAX],yvalue[MAX];
float s,s1,s2;
fp=fopen("rk_2.dat","w");
clrscr();
printf("\n\n");
fprintf(fp,"\n\n");
printf("Runge-Kutta Second Order ");
fprintf(fp,"Runge-Kutta Second Order ");
printf("\n\n");
fprintf(fp,"\n\n");
printf("\nEnter the lower bound of x : ");
fprintf(fp,"\nEnter the lower bound of x : ");
scanf("%f",&lower);
fprintf(fp,"%f",lower);
printf("\nEnter the upper bound of x : ");
fprintf(fp,"\nEnter the upper bound of x : ");
scanf("%f",&upper);
fprintf(fp,"%f",upper);
printf("\nEnter the value of y(lower): ");
fprintf(fp,"\nEnter the value of y(lower): ");
scanf("%f",&y1);
fprintf(fp,"%f",y1);
printf("\nEnter the value of h : ");
fprintf(fp,"\nEnter the value of h : ");
scanf("%f",&h);
fprintf(fp,"%f",h);
xvalue[i]=lower;
yvalue[i]=y1;
for(i=1;xvalue[i]<=upper;i++)
{
xvalue[i+1]=xvalue[i]+h;
count=count+1;
}
for(i=1;i<=count;i++)
{
s1=equation(xvalue[i],yvalue[i]);
s2=equation(xvalue[i]+h,yvalue[i]+(h*s1));
s=(s1+s2)/2;
yvalue[i+1]=yvalue[i]+(h*s);
}
printf("\n\n");
fprintf(fp,"\n\n");
printf("The complete solution of the differential equation is ");
fprintf(fp,"The complete solution of the differential equation is ");
printf("\n\n");
fprintf(fp,"\n\n");
for(i=1;i<=count;i++)
{
printf(" %d %.4f %.4f ",i,xvalue[i],yvalue[i]);
fprintf(fp," %d %.4f %.4f ",i,xvalue[i],yvalue[i]);
printf("\n");
fprintf(fp,"\n");
}
fclose(fp);
getch();
}














Range kutta method 4
#include<stdio.h>
#include <math.h>
#include<conio.h>
//dy/dx = 1 + y^2
#define F(x,y) 1 + (y)*(y)
void main()
{
double y0,x0,y1,n,h,f,k1,k2,k3,k4;
clrscr();
printf("\nEnter the value of x0: ");
scanf("%lf",&x0);
printf("\nEnter the value of y0: ");
scanf("%lf",&y0);
printf("\nEnter the value of h: ");
scanf("%lf",&h);
printf("\nEnter the value of last point: ");
scanf("%lf",&n);
for(; x0<n; x0=x0+h)
{
f=F(x0,y0);
k1 = h * f;
f = F(x0+h/2,y0+k1/2);
k2 = h * f;
f = F(x0+h/2,y0+k2/2);
k3 = h * f;
f = F(x0+h/2,y0+k2/2);
k4 = h * f;
y1 = y0 + ( k1 + 2*k2 + 2*k3 + k4)/6;
printf("\n\n k1 = %.4lf ",k1);
printf("\n\n k2 = %.4lf ",k2);
printf("\n\n k3 = %.4lf ",k3);
printf("\n\n k4 = %.4lf ",k4);
printf("\n\n y(%.4lf) = %.3lf ",x0+h,y1);
y0=y1;
}
getch();
}


http://books.google.co.in/books?id=f4f2wNPv5hYC&pg=PA60&lpg=PA60&dq=schur's
+lemma+theorem&source=bl&ots=2EuTRX6O5d&sig=sxKUXH18pZ0xoDpl4QFeG10bGRI&hl=
en&sa=X&ei=OJeMUZKELMrZrQf33IHAAw&ved=0CEcQ6AEwAw#v=onepage&q=schur's%20lem
ma%20theorem&f=false

You might also like