Showing posts with label code generator in c. Show all posts
Showing posts with label code generator in c. Show all posts

Wednesday, May 29, 2013

Solution of Ordinary Differential Equation using Runge-Kutta Method | RK4 method for ODE Solution in C

In numerical analysis, the Runge–Kutta methods are an important family of implicit and explicit iterative methods for the approximation of solutions of ordinary differential equations. These techniques were developed around 1900 by the German mathematicians C. Runge and M. W. Kutta.

There are many variants of the Runge-Kutta method, but the most widely used one is the following known as RK-4 method:
Given
y' = f(x,y)
y(xn) = yn
we compute in turn
k1 = hf(xn,yn)
k 2 = hf (xn+h/2,yn+k1/2)
k3 = hf (xn+h/2,yn+k2/2)
k4 = hf(xn + h, yn + k3)
yn+1 = yn + (k1 + 2*k2 + 2*k3 + k4 )/6

This algorithm can be implemented  using the following source code in C:

Saturday, May 18, 2013

Code Generator in C

The following code generates the code itself. The code seems to be simple but it's little bit tricky and is FAQ for programmers in an interview.

```
`#include"stdio.h"`
`#include"conio.h"`
`char *s="#include%c#``include%cchar *s=%c%s%c;%cvoid main()%c{%cclrscr();-%cprintf(s,10,10,34,s,34,10,10,10,10,10,10);%cgetch();%c}";`
`void main()``{`
`//clrscr();`
`printf(s,10,10,34,s,34,10,10,10,10,10,10);`
`getch();`
`}`
```
``````