this code is used to write a finite differential equation...
example:
y ’’(x)+ y(x) = 0
y(0)=1 ; y'(0)=0
delta x = 0.01 ; x0= 0
At X0 = 0
y ’’(x) = - y(x)
y ’’(0) = - y(0)
= -1
f ’( x + ∆x) = f ’’(x) ∆x + f ’(x)
f ’( 0 + 0.01) = f ’’(0) * 0.01+ f ’(0)
f ’(0.01) = - 0.01+ 0
= - 0.01
f( x + ∆x) = f ’(x) ∆x + f(x)
f( 0+ 0.01) = f ’(0) * 0.01+ f(0)
f (0.01) = 0 + 1
= 1
At X0 = 0.01
y ’’(0.01) = - y(0.01)
y ’’(0.01) = - 1
f ’( x + ∆x) = f ’’(x) ∆x + f ’(x)
f ’( 0.01 + 0.01) = f ’’(0.01) * 0.01+ f ’(0.01)
f ’(0.02) = - 0.01- 0.01
=- 0.02
f( x + ∆x) = f ’(x) ∆x + f(x)
f( 0.01 + 0.01) = f ’(0.01) * 0.01+ f(0.01)
f (0.02) = - 0.01 * 0.01 + 1
= 0.9999
and so on....
At X0 = 0.04
y ’’(0.04) = - y(0.04)
y ’’(0.04) = - 0.9994001
f ’( x + ∆x) = f ’’(x) ∆x + f ’(x)
f ’( 0.04 + 0.01) = f ’’(0.04) * 0.01+ f ’(0.04)
f ’(0.05) = (-0.9994001)* 0.01– 0.039996
= - 0.04995401
f( x + ∆x) = f ’(x) ∆x + f(x)
f( 0.04 + 0.01) = f ’(0.04) * 0.01+ f(0.04)
f (0.05) = - 0.039996 * 0.01 + 0.9994001
= 0.999
using finite DE
y (0.05) = 0.999
using analytical method
y (x) = cos x y(0.05) = cos (0.05)
Y(0.05) = 0.99875
correct!!
when i make my source code, there are many errors.. please tell me what went
wrong please.... this is my source code...
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define xd 0.01
int main()
{
int x2;
int y0=1;
int y1=0;
float f1(float y1, float y0);
float prog(void);
char buff[BUFSIZ];
printf("enter value of x:");
x2 = atof(gets(buff));
/* This is the main formula */
float f1(float y1, float y0)
{ float ans1, ans2, ans3;
ans1 = -y0;
ans2 = (ans1 * xd) + y1;
ans3 = (y1 * xd) + y0;
return ans3;
}
float prog()
{
float x1 = xd + x2;
do {
z = f1(y1,y0);
} while ( z >= x1 );
return x1;
}
[Non-text portions of this message have been removed]