You are on page 1of 5

Problem No: PCRD-21

Write an efficient C program to solve the Initial Value


Problem (I.V.P)

3
𝑑𝑦
𝑑𝑥 ( )
= 𝑥 𝑝 + 𝑥 𝑦 , 𝑦(0) = 1. 0

by Picard’s successive approximation and compute


numerical solution in the interval [0, 0. 5] with step
length 0.1, correct to 5𝐷.

where p = 2.1
/*CC-14 Numerical Methods Practical 2021
NAME: PRABHAKAR SONAR
CU ROLL NO: 183613-21-0045
PROGRAM FOR PICARDS RULE
Date Of Submission: 11/07/2021*/
#include<conio.h>
#include<stdio.h>
#include<math.h>
#define p 2.1
float y(float x)
{
float g;
g=1+p*(pow(x,2)/2.0)+(pow(x,5)/5.0);
return(g);
}
float y2(float x)
{
float i;
i=1+p*(pow(x,2)/2.0)+(pow(x,5)/5.0)+p*(pow(x,7)/14.0)+(pow(x,10)/50.0);
return(i);
}
float y3(float x)
{
float j;

j=1+p*(pow(x,2)/2.0)+(pow(x,5)/5.0)+p*(pow(x,7)/14.0)+(pow(x,10)/50.0)+p*(pow(x,12)/168.0)+(
pow(x,15)/750.0);
return(j);
}
float y4(float x)
{
float k;

k=1+p*(pow(x,2)/2.0)+(pow(x,5)/5.0)+p*(pow(x,7)/14.0)+(pow(x,10)/50.0)+p*(pow(x,12)/168.0)+(
pow(x,15)/750.0)+(pow(x,17)/2856.0)+(pow(x,20)/15000.0);
return(k);
}
float y5(float x)
{
float l;

l=1+p*(pow(x,2)/2.0)+(pow(x,5)/5.0)+p*(pow(x,7)/14.0)+(pow(x,10)/50.0)+p*(pow(x,12)/168.0)+(
pow(x,15)/750.0)+(pow(x,17)/2856.0)+(pow(x,20)/15000.0)+(pow(x,22)/62832.0)+(pow(x,25)/37
5000.0);
return(l);
}
main()
{
float x,Y,h,a,b,t=1.0e-6,y0;
printf("Enter the value of step-lenght h : ");
scanf("%f",&h);
printf("Enter the value of a of interval [a,b] : ");
scanf("%f",&a);
printf("Enter the value of b of interval [a,b] : ");
scanf("%f",&b);
printf("Enter the value of y at y(x0) : ");
scanf("%f",&y0);
printf("\nY(%.1f)= %.5f(Correct upto 5D place)\n",a,y0);
for(x=a+h;x<=b;x+=h)
{

printf("\nx=%.1f\ty(%.1f)=%f\t\ty2(%.1f)=%f\t|y(x)-y2(x)|=%f\n",x,x,y(x),x,y2(x),fabs(y(x)-y2(x)));
if(fabs(y2(x)-y(x))<t)
{
printf("\nThe value of Y(%.1f)=%.5f(Correct upto 5D place)\n",x,y2(x));
}
else
{

printf("\nx=%.1f\ty2(%.1f)=%f\ty3(%.1f)=%f\t|y2(x)-y3(x)|=%f\n",x,x,y2(x),x,y3(x),fabs(y2(x)-y3(x)
));
if(fabs(y3(x)-y2(x))<t)
{
printf("\nThe value of Y(%.1f)=%.5f(Correct upto 5D place)\n",x,y3(x));
}
else
{

printf("\nx=%.1f\ty3(%.1f)=%f\ty4(%.1f)=%f\t|y3(x)-y4(x)|=%f\n",x,x,y3(x),x,y4(x),fabs(y3(x)-y4(x)
));
if(fabs(y4(x)-y3(x))<t)
{
printf("\nThe value of Y(%.1f)=%.5f(Correct upto 5D place)\n",x,y4(x));
}
else
{
printf("\nx=%.1f\ty4(%.1f)=%f\ty5(%.1f)=%f\t|y4(x)-y5(x)|=%f\n",x,x,y4(x),x,y5(x),fabs(y5(x)-y4(x)
));
if(fabs(y5(x)-y4(x))<t)
{
printf("\nThe value of Y(%.1f)=%.5f(Correct upto 5D place)\n",x,y5(x));
}
}
}
}
}
getch();
}

OUTPUT
Enter the value of step-lenght h : 0.1
Enter the value of a of interval [a,b] : 0.0
Enter the value of b of interval [a,b] : 0.5
Enter the value of y at y(x0) : 1.0

Y(0.0)= 1.00000(Correct upto 5D place)

x=0.1 y(0.1)=1.010502 y2(0.1)=1.010502 |y(x)-y2(x)|=0.000000

The value of Y(0.1)=1.01050(Correct upto 5D place)

x=0.2 y(0.2)=1.042064 y2(0.2)=1.042066 |y(x)-y2(x)|=0.000002

x=0.2 y2(0.2)=1.042066 y3(0.2)=1.042066 |y2(x)-y3(x)|=0.000000

The value of Y(0.2)=1.04207(Correct upto 5D place)

x=0.3 y(0.3)=1.094986 y2(0.3)=1.095019 |y(x)-y2(x)|=0.000033

x=0.3 y2(0.3)=1.095019 y3(0.3)=1.095019 |y2(x)-y3(x)|=0.000000

The value of Y(0.3)=1.09502(Correct upto 5D place)

x=0.4 y(0.4)=1.170048 y2(0.4)=1.170296 |y(x)-y2(x)|=0.000248

x=0.4 y2(0.4)=1.170296 y3(0.4)=1.170296 |y2(x)-y3(x)|=0.000000

The value of Y(0.4)=1.17030(Correct upto 5D place)


x=0.5 y(0.5)=1.268750 y2(0.5)=1.269941 |y(x)-y2(x)|=0.001191

x=0.5 y2(0.5)=1.269941 y3(0.5)=1.269945 |y2(x)-y3(x)|=0.000003

x=0.5 y3(0.5)=1.269945 y4(0.5)=1.269945 |y3(x)-y4(x)|=0.000000

The value of Y(0.5)=1.26994(Correct upto 5D place)

You might also like