Differential equation in fortran

Click For Summary
SUMMARY

The discussion focuses on implementing the fourth-order Runge-Kutta algorithm in Fortran for solving a system of differential equations with imaginary components. The equations provided are x'=(i)y *exp(iwt) and y'=(i)x*exp(iwt), where 'i' represents the imaginary unit and 'w' is a constant. The initial approach of defining x and y as real variables led to errors due to the complex nature of the equations. A recommended solution involves defining all variables, including x and y, as complex and utilizing the properties of complex exponentials to reformulate the equations into a system of real variables.

PREREQUISITES
  • Understanding of complex numbers and their representation in programming.
  • Familiarity with the fourth-order Runge-Kutta algorithm for numerical integration.
  • Proficiency in Fortran programming language, particularly with complex data types.
  • Knowledge of differential equations and their numerical solutions.
NEXT STEPS
  • Learn how to define and manipulate complex numbers in Fortran.
  • Study the implementation of the fourth-order Runge-Kutta method for complex differential equations.
  • Explore the conversion of complex differential equations into systems of real equations.
  • Investigate the use of complex exponentials and their properties in numerical computations.
USEFUL FOR

Mathematicians, physicists, and engineers involved in numerical simulations, particularly those working with complex differential equations in Fortran.

nirajaryal
Messages
1
Reaction score
0
I need to do numerical computation by fourth order Runge Kutta Algorithm
in fortran. But I stuck in programming because the differential
equation contains imaginary part.

Take for e.g. the set of diff.equation are
x'=(i)y *exp(iwt) ;where i is imaginary no. and w is constant!
y'=(i)x*exp(iwt)

I tried to define complex function f and g as
f=(0,y *exp(iwt))
g=(0,x *exp(iwt))

and i defined x and y as real (because the argument of the complex
no.has to be real,right?/otherwise it doesn't accept)
But after every iteration,the x and y becomes real as
x=x0+some linear combination of the function f(which is complex)//and
real +complex gives complex no. and hence shows error!
So i unable to proceed further! So how should I proceed?
 
Technology news on Phys.org
nirajaryal said:
Take for e.g. the set of diff.equation are
x'=(i)y *exp(iwt) ;where i is imaginary no. and w is constant!
y'=(i)x*exp(iwt)

I tried to define complex function f and g as
f=(0,y *exp(iwt))
g=(0,x *exp(iwt))

and i defined x and y as real (because the argument of the complex
no.has to be real,right?

That is wrong, because your definitions of f and g are not the same as your differential equation.

Try something like this:
define ZI as a complex constant = (0.0, 1.0)
Make X, Y, F and G all complex
and then do
F = ZI * X * exp(ZI * W * T)

Alternatively, you could convert this to a set of equations in 4 real variables, the real and imaginary parts of x and y. Since exp(iwt) = cos wt + i sin wt

If you write x = xr + i xi and y = yr + i yi, where xr, xi, yr, yi are real, then

i * y *exp(iwt) = (i yr - yi) (cos wt + i sin wt)
= -yi cos wt + yr sin wt + i (yr cos wt - yi sin wt)

So you would have

xr' = -yi cos wt + yr sin wt
xi' = yr cos wt - yi sin wt
and similar equations for yr' and yi'
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K