help-octave
[Top][All Lists]

## Re: Deal with the complex functions

 From: Miroslaw Kwasniak Subject: Re: Deal with the complex functions Date: Mon, 15 Jan 2007 20:53:53 +0100 User-agent: Mutt/1.5.9i

```On Mon, Jan 15, 2007 at 07:58:41PM +0800, marchriver wrote:
> Hi
> I am trying to solve the complex differential equations with octave.
> However from the manual and examples, it seems to limit to real
> equations. And when I write the equation in the form
> dx=i*a*t+i*b*x+i*c*x^2
> The result said it contains image numbers. Does octave can deal with
> complex equations? Or I have to separate the real and image part to
> solve? But the real equations I have to solve are quite complicit and a
> large number. It will be very hard to do so. Can anyone give me some
> clues?

It's  easy ;)

Assuming that your complex valued function is:

function dx=f(t,x);
a=-1;b=-.5;c=.01;
dx=i*a*t+i*b*x+i*c*x^2;
endfunction

just write a wrapper:

function DX=freal(t,X);
n=1:2:length(X);
x=complex(X(n),X(n+1));
dx=f(t,x);
DX=zeros(size(X));
DX(n)=real(x)
DX(n+1)=imag(dx);
endfunction

... and calculate it :

[tout, xout] = ode45('freal',[0 8],[1; -11]);
n=1:2:columns(xout);
xcomplex=complex(xout(:,n),xout(:,n+1));

```