Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views1 page

Runge Kutta (4th Order Order) :: Printf ("Invalid Guess") ) Else

Uploaded by

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

Runge Kutta (4th Order Order) :: Printf ("Invalid Guess") ) Else

Uploaded by

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

#include<stdio.

h> LSF
Simpson 1/3 rd Rule: Simpson 3/8th Rule Bisection Method: Euler’s Method:
Trapezoidal Rule:
#include<conio.h> #include<stdio.h> #include<stdio.h> #include<stdio.h> #include<stdio.h>
#include<stdio.h>
#include<math.h> #include<conio.h> #include<conio.h> #include<conio.h> #include<conio.h>
#include<conio.h>
void main() #include<math.h> #include<math.h> #include<math.h> #include<math.h>
#include<math.h>
{ float f (float x); floatf(float x); void main() float f(float x, float y);
int i,n; float f(float x);
void main() void main(){ { void main()
float x[15],y[15]; void main()
{ int i,n, k=3; float a,b,x2,x3,f; {
float sumx=0.0,sumy=0.0,sumxy=0.0,sumxsq=0.0,a,b; {
int i,n; float ul,ll,h, sum1, sum2, area; clrscr(); float x,y,xn,h,y1;
clrscr(); int i,n;
prin ("enter the number of data points:");
float ul,ll,h,sum1, sum2, term, area; clrscr(); Printf(“\n bisection method\n”); clrscr();
float ul,ll,h,sum1, sum2, term, area;
scanf("%d",&n); clrscr(); Printf(“Enter the value ll and ul\n”); Printf(“equation =(3*x2)+3\n”); Printf(“\n Enter the initial values of x and y, final
clrscr();
prin ("enter the value of x:\n"); printf(“Enter the value ll and ul\n”); Scanf(“%f%f”,&ll,&ul); Printf(“\n Enter the interval\n”); values of x and h\n”);
printf(“Enter the value ll and ul\n”);
for(i=1;i<=n;i++) scanf(“%f%f”,&ll,&ul,); Printf (“Enter the number of intervals \n”) ; Scanf(“%f%f”,&a,&b”); Scanf(“%f%f%f%f”,&x,&y,&xn,&h);
scanf(“%f%f”,&ll,&ul);
{ printf (“Enter the number of intervals\n”); Scanf(“%d”,&n); Printf(“\n %f%f”,a,b); Printf(“\n x\t\t y\n”);
scanf("%f",&x[i]); printf (“Enter the number of intervals\n”);
scanf(“%d”,&n); h=(ul-ll)/n; x2=0.0; Printf(“%f\t\t%f”,x,y);
} scanf(“%d”,&n);
h=(ul-ll)/n; sum1=f(ll)+f(ul); Printf(“a\t b\t x2\n”); while(x<=xn)
prin ("enter the values of y:\n"); h=(ul-ll)/n;
Sum1=f(ll)+4.0*f(ll+h)+f(ul); Sum2=0.0; do {
for(i=1;i<=n;i++) sum1=f(ll)+f(ul);
{ sum2=0.0; for(i=1;i<=n-1;i=i++) { y1=y+h*f(x,y);
sum2=0.0;
scanf("%f",&y[i]); for(i=2;i<=n-2;i=i+2) {if(i==k) { x3=x2; y=y1;
for(i=0;i<n;i++)
} { term=2.0*f(ll+i*h)+4.0*f(ll+(i+1)*h); sum2=sum2+2*f(ll+i*h); x2=(a+b)/2.0; x=x+h;
{
for(i=1;i<=n;i++) sum2-sum2+term; k=k+3; } f=(3^{*}\times2)+3; Printf(“\n %f\t\t %f”,x,y);
{ term=2.0*f(ll+i*h);
} else Printf(“\n %f \t %f\t %f”,a,b,x2); }
sumx+=x[i]; sum2=sum2+term;
area=(sum1+sum2)*h/3.0; sum2=sum2+3*f(ll+i*h); } if(f<0) getch();
sumy+=y[i]; }
Printf(“the value of integral =%f”, area); area=((3*h)/8)*(sum1+sum2); a=x2; }
sumxy+=(x[i]*y[i]); area=(sum1+sum2)*h/2.0;
sumxsq+=(x[i]*x[i]);
getch(); printf(“the value of integral =\%f”, area); else float f (float x, float y)
printf(“the value of integral =%f”, area);
} } getch();} b=x2 {
getch();
b=(sumx*sumy-n*sumxy)/((sumx*sumx)-(n*sumxsq)); float f (float x) float f (float x) } float fun;
}
a=(sumy-b*sumx)/n; { { while (x3!=x2); fun=(1+x)*y*y/2;
float f (float x){
prin ("the values of a=%f and b=%f",a,b); float fun; float fun; Printf(“\n The root of the equation =%f”,x2); return(fun);
prin ("the equa on is y=(%f)x+(%f)",b,a); float fun;
fun= exp(x)*sin(x); fun=exp(x)*sin(x); getch(); }
getch(); fun= exp(x)*sin(x);
return(fun); return(fun); }
} return(fun);
} }
}
}

Runge kutta (2nd order): Runge kutta (4th order order): #include<stdio.h> Newton-RHapson #include<stdio.h> LSF Trapezoidal Rule: Simpson 1/3 rd Rule:
#include<stdio.h> #include<stdio.h> #include<math.h> #include<conio.h> #include<stdio.h> #include<stdio.h>
#include<conio.h> float f(float x); #include<math.h> #include<conio.h>
#include<conio.h> #include<conio.h>
#include<math.h> int main() void main()
#include<math.h> { #include<math.h> #include<math.h>
float f (float x, float y); {
float f (float x, float y); void main() float x0,x1,x2,f0,f1,f2,e,i=1; float f(float x); float f (float x);
int i,n;
void main() { printf("Enter initial values and permitted error:\n"); float x[15],y[15]; void main() void main()
int n,i scanf("%f%f%f",&x0,&x1,&e); { {
float x,y,xn,h,y1,k1,k2; float sumx=0.0,sumy=0.0,sumxy=0.0,sumxsq=0.0,a,b;
float x,y,xn, h,y1,k1,k2,k3,k4; f0=f(x0); int i,n;
clrscr(); f1=f(x1);
clrscr(); int i,n;
clrscr(); prin ("enter the number of data points:"); float ul,ll,h,sum1, sum2, term, area; float ul,ll,h,sum1, sum2, term, area;
Printf(“\n Enter the initial values of x and y, Printf(“\n Enter the initial values of x and y, final if((f0*f1)>0)
{ scanf("%d",&n); clrscr(); clrscr();
final values of x and h\n”); values of x and h\n”);
prin ("enter the value of x:\n");
Scanf(“%f%f%f%f”,&x,&y,&xn,&h); Scanf(“%f%f%f%f”, &x,&y,&xn,&h); printf("Invalid guess"); printf(“Enter the value ll and ul\n”); printf(“Enter the value ll and ul\n”);
} for(i=1;i<=n;i++) scanf(“%f%f”,&ll,&ul,);
Printf(“\n x\t\t y\n”); Printf(“\n x \t y\n”); scanf(“%f%f”,&ll,&ul);
else {
Printf(“%f\t\t%f”,x,y);
Printf(“\n %f \t %f”,x,y); printf (“Enter the number of intervals\n”); printf (“Enter the number of intervals\n”);
n=(xn-x)/h, { scanf("%f",&x[i]);
while(x<=xn) printf("x0\t\t\tx1\t\t\tx2\t\t\tf2\t\t\tIterations\n"); } scanf(“%d”,&n); scanf(“%d”,&n);
for(i=1;i<=n;i++)
{ { do prin ("enter the values of y:\n"); h=(ul-ll)/n; h=(ul-ll)/n;
k1=h*f(x,y); k1=h*f(x,y); { for(i=1;i<=n;i++) sum1=f(ll)+f(ul); Sum1=f(ll)+4.0*f(ll+h)+f(ul);
k2=h*f(x+h/2,y+k1/2); x2=(x0+x1)/2; { sum2=0.0; sum2=0.0;
k2=h*f(x+h,y+k1); f2=f(x2);
k3=h*f(x+h/2,y+k2/2); scanf("%f",&y[i]); for(i=0;i<n;i++) for(i=2;i<=n-2;i=i+2)
y1=y+(k1+k2)/2; k4=h*f(x+h,y+k3); printf("%f\t%f\t%f\t%f\t%f\n",x0,x1,x2,f2,i); }
y=y1; if(f0*f2<0.0) { { term=2.0*f(ll+i*h)+4.0*f(ll+(i+1)*h);
y1=y+(k1+2*k2+2*k3+k4)/6; for(i=1;i<=n;i++)
x=x+h; y=y1; x1=x2; term=2.0*f(ll+i*h); sum2-sum2+term;
{
printf(“\n%f\t\t %f”,x,y); x=x+h; else sumx+=x[i]; sum2=sum2+term; }
} printf(“\n %f \t %f”,x+h,y1); x0=x2;
sumy+=y[i]; } area=(sum1+sum2)*h/3.0;
} getch(); } i=i+1; Printf(“the value of integral =%f”, area);
getch(); } while(fabs(f2)>e); sumxy+=(x[i]*y[i]); area=(sum1+sum2)*h/2.0;
float f (float x, float y) sumxsq+=(x[i]*x[i]); printf(“the value of integral =%f”, area); getch();
} { printf("\n The root is %f\n",x2);
float f (float x, float y) float fun; } } getch(); }
return 0; b=(sumx*sumy-n*sumxy)/((sumx*sumx)- } float f (float x)
{ fun=(1+x)*y*y/2;
} (n*sumxsq)); {
float fun; return(fun); float f (float x){
float f(float x) a=(sumy-b*sumx)/n;
fun=(1+x)*y*y/2;
} float fun; float fun;
{ prin ("the values of a=%f and b=%f",a,b);
return(fun); float fun; prin ("the equa on is y=(%f)x+(%f)",b,a); fun= exp(x)*sin(x); fun= exp(x)*sin(x);
fun=(exp(x)-3*x); getch(); return(fun); return(fun);
}
return fun; } } }
} }

Runge kutta (4th order order):


#include<stdio.h>
#include<conio.h>

Printf(“\n Enter the initial values of x and y,


Printf(“\n Enter the initial values of x and y,

#include<math.h>
float f (float x, float y);
void main()

Scanf(“%f%f%f%f”,&x,&y,&xn,&h);
{
Scanf(“%f%f%f%f”,&x,&y,&xn,&h);

int n,i
Printf(“\n %f \t %f\t %f”,a,b,x2);

float x,y,xn, h,y1,k1,k2,k3,k4;


Printf(“equation =(3*x2)+3\n”);
Printf(“\n Enter the interval\n”);
Printf(“\n bisection method\n”);

clrscr();
Printf(“\n Enter the initial values of x and y, final values of x and h\n”);
Scanf(“%f%f%f%f”, &x,&y,&xn,&h);
Printf(“\n x \t y\n”);
Printf(“\n %f \t %f”,x,y);
Scanf(“%f%f”,&a,&b”);

Runge kutta (2nd order):

n=(xn-x)/h,
final values of x and h\n”);
final values of x and h\n”);

for(i=1;i<=n;i++)
Printf(“\n %f%f”,a,b);

Printf(“\n %f\t\t %f”,x,y);

printf(“\n%f\t\t %f”,x,y);
Printf(“a\t b\t x2\n”);

{
f=(3^{*}\times2)+3;

float x,y,xn,h,y1,k1,k2;
float f (float x, float y);

Printf(“%f\t\t%f”,x,y);
k1=h*f(x,y);
Bisection Method:

float f (float x, float y)


Printf(“%f\t\t%f”,x,y);
float f(float x, float y);

float f (float x, float y)


#include<conio.h>
#include<math.h>

k2=h*f(x+h/2,y+k1/2);
#include<stdio.h>

Printf(“\n x\t\t y\n”);


Printf(“\n x\t\t y\n”);

k3=h*f(x+h/2,y+k2/2);
float a,b,x2,x3,f;

k2=h*f(x+h,y+k1);
while (x3!=x2);

#include<conio.h>

k4=h*f(x+h,y+k3);
#include<conio.h>

#include<math.h>
#include<stdio.h>
#include<math.h>
#include<stdio.h>

y1=y+(k1+k2)/2;
Euler’s Method:
x2=(a+b)/2.0;

y1=y+(k1+2*k2+2*k3+k4)/6;
float x,y,xn,h,y1;

y=y1;
y1=y+h*f(x,y);
void main()

x=x+h;
while(x<=xn)
while(x<=xn)

k1=h*f(x,y);

printf(“\n %f \t %f”,x+h,y1);
void main()
void main()

} getch(); }
clrscr();

x2=0.0;

x3=x2;

if(f<0)

float f (float x, float y)


a=x2;

{
b=x2

clrscr();

getch();
clrscr();

getch();

x=x+h;
else

float fun;
x=x+h;

y=y1;
do

fun=(1+x)*y*y/2;
y=y1;
{

return(fun);
}
{

{
{

You might also like