Euler Method
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main(void)
{
clrscr();
float y=5.0,h=1.0;
float x=0.0,error,z=2.763;
for(int i=0;i<3;i++)
{
double fact1=3*(exp(-x));
double fact2=0.4*y;
y=y+(fact1-fact2)*(h);
x++;
printf("ans: %f\n",y);
}
error=((z-y)/z)*100;
if(error<1)
error*=-1;
printf("percentage: %f\n",error);
getch();
}
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main(void)
{
clrscr();
float y=5.0,h=1.0;
float x=0.0,error,z=2.763;
for(int i=0;i<3;i++)
{
double fact1=3*(exp(-x));
double fact2=0.4*y;
y=y+(fact1-fact2)*(h);
x++;
printf("ans: %f\n",y);
}
error=((z-y)/z)*100;
if(error<1)
error*=-1;
printf("percentage: %f\n",error);
getch();
}
No comments:
Post a Comment