help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calculating the divergence


From: J Stasko
Subject: Calculating the divergence
Date: Tue, 2 Aug 2011 07:57:31 -0700

I noticed that for the del2 operator I can get much faster execution if I read del2.m and strip out most of the excess stuff which checks for options, etc.   But my question here is not that I'm proposing this as a replacement, instead, I'm asking if I did this right...  Please think along with me.

Firstly, I'm working with Dirichlet boundary conditions, and I arbitrarily set the edge of my matrix to have these constant boundary conditions throughout the problem.  There is a heat-generating source in the middle of the world, and there is some geometry throughout the world, and of course, at the edge of the matrix (that is, at the edge of the world), the temperature is always 293K.  Air is the conducting medium between the geometry and the edge of the universe.

I noticed that the del2.m file is broken up into three sections:
- initialization and option management
- calculation of the central areas of the matrix
- calculation of the edges

Since the edges aren't necessary (that is, they represent the boundary conditions), I ignore the last section.    Also, I'm working only with 2-d matrices right now.  

So to calculate the central areas of the matrix, I need an array that computes the del2 and another which sets the edges to zero:

## Declare the derivative matrix
dmat = diag(-1*ones(1,Nux-1),1) + 2*eye(Nux) + \
    diag(-1*ones(1,Nux-1),-1);
dmat = dmat ./ -4.0;

## Declare the blanking matrix
blankmat = blkdiag([0],ones(Nux-2,Nuy-2),[0]);


Next, here's the calculation for my del2:

( (x*dmat)+(dmat*x) ) .* blankmat  / dx / dy


So I go ahead and run this in my heat model and get a picture that looks exactly like what I was getting with the del2 operator after 50 cycles.  I also calculated the difference, and only the area adjacent to the edges is different, and that only by 0.001K, which is quite acceptable and certainly within numerical error (representing an error of 3.4e-06).

The increase in speed is about 25x over using del2.m

The pictures are located here: http://imgur.com/a/ghpjD

Did I do this correctly?  It looks good and matches what I have in the lab, and the errors are small. 

... Now I have to figure out how to make a Jacobian of this thing.  

Thanks.

-John

reply via email to

[Prev in Thread] Current Thread [Next in Thread]