answersLogoWhite
C Programming
Numerical Series Expansion

C programming of Runge-Kutta method?


Top Answer
User Avatar
Wiki User
Answered 2011-01-25 14:29:14

PROGRAM :-

/* Runge Kutta for a set of first order differential equations */

#include

#include

#define N 2 /* number of first order equations */

#define dist 0.1 /* stepsize in t*/

#define MAX 30.0 /* max for t */

FILE *output; /* internal filename */

void runge4(double x, double y[], double step); /* Runge-Kutta function */

double f(double x, double y[], int i); /* function for derivatives */

void main()

{

double t, y[N];

int j;

output=fopen("osc.dat", "w"); /* external filename */

y[0]=1.0; /* initial position */

y[1]=0.0; /* initial velocity */

fprintf(output, "0\t%f\n", y[0]);

for (j=1; j*dist<=MAX ;j++) /* time loop */

{

t=j*dist;

runge4(t, y, dist);

fprintf(output, "%f\t%f\n", t, y[0]);

}

fclose(output);

}

void runge4(double x, double y[], double step)

{

double h=step/2.0, /* the midpoint */

t1[N], t2[N], t3[N], /* temporary storage arrays */

k1[N], k2[N], k3[N],k4[N]; /* for Runge-Kutta */

int i;

for (i=0;i

{

t1[i]=y[i]+0.5*(k1[i]=step*f(x,y,i));

}

for (i=0;i

{

t2[i]=y[i]+0.5*(k2[i]=step*f(x+h, t1, i));

}

for (i=0;i

{

t3[i]=y[i]+ (k3[i]=step*f(x+h, t2, i));

}

for (i=0;i

{

k4[i]= step*f(x+step, t3, i);

}

for (i=0;i

{

y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0;

}

}

double f(double x, double y[], int i)

{

if (i==0)

x=y[1]; /* derivative of first equation */

if (i==1)

x= -0.2*y[1]-y[0]; /* derivative of second equation */

return x;

}

123
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Loading...

Still Have Questions?

Related Questions

What is the method of programming when using C plus plus?

C++ allows any combination of structured programming, procedural programming, object-oriented programming and template metaprogramming.


In computer programming C stand for?

C and it's variants (C++, C#, etc...) are all programming languages. C is simply a method of using words and alphanumeric characters to create a set of instructions that form a program.


How do you compute the holzer method in C programming?

Hafner/Maass have done it in Fortran. Maybe of help by translating?


What is Polymorphism in c?

c programming is structured programming


What is programming with c plus plus?

Programming with C++ is writing computer programs using the C++ programming language.


What is the unit of programming in c?

The unit of programming in C is the function.


What is c and c in computer programming?

C and C++ are both high-level programming languages.


What is C plus plus programming?

It is high-level programming using the C++ programming language.


What programming language is best for machine learning?

c and c++ languages are the best programming languaghes c and c++ languages are the best programming languaghes


Difference of C programming and c plus plus programming?

C is procedural based programming while C++ is extension of C and it follows object oriented technique


What is the function of symboland in C programming?

The symbol and (ampersand, &amp;) in C and C++ programming is the bitwise inclusive or operator. If there are two ampersands (&amp;&amp;) it is a relational inclusive or operator. As a unary operator, it means to take the address of something. In C++, it can also be overridden in a class method to mean nearly anything else.


C programming code for gauss Jordon method to solve quadratic equation?

how to use gauss programming to find LM unit root test with structural breaks and kpss


What is the meaning of a method in Java programming?

a method is a variable


What is a name of a programming language?

C++ is the name of a programming language.


Create a spiral in C programming?

create spiral in c programming?


What do you understand by the left and right parenthesis in main method in C programming?

I understand they have the same meaning as they do for any function in C; to separate the function name from its arguments.


What software is used for the C programming?

C++ programming. Currently Is use "Turbo C plus plus" to practice programmingC programming Is use "Turbo C" or called ( C compiler )Also see this articleSoftware_used_to_create_c_program


What has the author Robert Lafore written?

Robert Lafore has written: 'Object-oriented programming in Microsoft C++' -- subject(s): Object-oriented programming (Computer science), C++ (Computer program language), C. 'Microsoft C. Programming for the I.B.M.Personal Computer' 'Object-oriented programming in C++' 'Windows Programming Made Ridiculously Easy Book' 'The Waite Group's C Programming Using Turbo C++ (The Waite Group)' 'Microsoft C programming for the IBM' 'The Waite Group's Microsoft C programming for the PC' -- subject(s): C (Computer program language), IBM microcomputers, Microsoft C (Computer program), Microsoft C., Programming


Is C plus plus good for Embedded programming or not?

C and C++ programming is good for embedded programming. However, embedded implies long running, and that means the possibility of memory fragmentation. You will need to spend time working out or acquiring a method of memory management, such as the use of Smart Pointers and Garbage Collection. This is not a trivial task, but it is a necessary task.


What is the different between c and c plusplus?

C is a procedure oriented programming and C++ is a object oriented programming.C++ is a superset of C.


What is a C compiler as used in C programming?

In C programming, C compiler is user to translate C source into C object module.


What level of programming language is C programming?

C is a high-level language.


What is a programming in c?

'C' is a computer programming language developed by Dennis Ritchie.


What are 3 programming languages?

C, C++ and Java are three programming languages.


What is the difference between C programming and CPP programming?

The C and C++ languages are, at their core, very similar. C++ adds Object Oriented Programming, and several other enhancements, to the C language.