Eulers Method

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Assignment

// Euler.cpp : WACP to evaluate y(1,2) for the differential eq n

dy
=x+ y
dx

where y(0)=1; taking h=0.2 . Correct upyo 3 decimal places.


//
The Code is :
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
float f(float x, float y)
{
return (x+y);
}
int main(int argc, char* argv[])
{
float x,y,h,x1;
printf ("\n Enter the value of Xo=");
scanf ("%f", &x);
printf ("Enter the value of Yo=");
scanf ("%f", &y);
printf ("Enter the value of h=");
scanf ("%f", &h);
printf ("Enter the value of X where you want to find y ");
scanf ("%f", &x1);
while (x<x1)
{
y=y+h*f(x,y);
x=x+h;
}
printf ( "Required value of Y at X=%0.2f is %0.3f" , x1,y);
return 0;
}

OUTPUT
Enter the value of Xo=0
Enter the value of Yo=1
Enter the value of h=0.2
Enter the value of X where you want to find y 1.2
Required value of Y at X=1.20 is 3.772Press any key to continue

You might also like