Last edited by KermMartian on 20 Nov 2016 02:34:36 pm; edited 2 times in total

On a whim, I wrote a program in matlab to simulate the modes of a 2D circular membrane vibrating in 3D space, also known as a drum. The program takes the two variables for the mode of the membrane (n,m), where n is the number of radial nodes, and m is the number of concentric nodes (1=none only center and edge, 2=center, edge, and 1 more, etc), then generates a plot of the membrane, using Laplacian smoothing to create the surface. However, it still has a significant number of flaws, so if anyone would like to mess with my code and see if they can improve it a bit, I'd appreciate the help. Check out some sample plots and the code itself below.

%generate the polar mesh
for a=1:length(rad)
x(:,a)=rad(a)*cos(theta);
y(:,a)=rad(a)*sin(theta);
movable(1:length(theta),a)=1;
end

%set up immovable radii
if (n>0)
for a=1:n
myangle=(a-1)*(pi./n);
movable(1+round(myangle./gran_theta),:)=0;
z(1+round(myangle./gran_theta),:)=0;
movable(1+round((pi+myangle)./gran_theta),:)=0;
z(1+round((pi+myangle)./gran_theta),:)=0;
end
end

% set up immovable concentric circles
if (m>0)
for a=1:m+1
myrad=(a-1)*(radmax/m);
movable(:,1+round(myrad./gran_rad))=0;
z(:,1+round(myrad./gran_rad))=0;
end
end

%set up initial z values to smooth
rowstart = 1;

for b=2:length(rad)-1
if (m==0 || movable(2,b)==1)
blockstart = rowstart;
for a=1:length(theta)
if movable(a,b)==1
z(a,b)=blockstart;
else
blockstart=blockstart*-1;
end
end
else
rowstart = rowstart*-1;
end
end

No worries. It currently fails at two things:
1) there's a discontinuity at the boundaries between 0 and 360 degrees (it's rectangular mapped to polar)
2) It doubles the mode values for m because I misread my notes from Musical Instrument Design class. No biggie.

Welcome to Cemetech. Yes, I did indeed perform a Numerical Laplacian in the discretized domain, but I figured no one here would know what I was talking about if I said that. I'm running 2007a at the moment; I'm surprised the movie didn't work.

I was on ticalc.org and noticed the TI-83 programming contest so I entered that and ever since, I've been intrigued with the projects that you work on. I'm guessing you're an EE, but I'm not 100% sure.

Anyway, once I saw that you like to mess around with Matlab, I had to check it out. I do quite a bit of stuff on Matlab myself and that's what brought me to this.

I was on ticalc.org and noticed the TI-83 programming contest so I entered that and ever since, I've been intrigued with the projects that you work on. I'm guessing you're an EE, but I'm not 100% sure.

Anyway, once I saw that you like to mess around with Matlab, I had to check it out. I do quite a bit of stuff on Matlab myself and that's what brought me to this.

That's correct, I'm a senior undergraduate EE. I'm glad to hear you are intrigued by my projects, and it would be neat if you'd post some of your own Matlab projects

%generate the polar mesh
for a=1:length(rad)
x(:,a)=rad(a)*cos(theta);
y(:,a)=rad(a)*sin(theta);
movable(1:length(theta),a)=1;
end

%set up immovable radii
if (n>0)
for a=1:n
myangle=(a-1)*(pi./n);
movable(1+round(myangle./gran_theta),:)=0;
z(1+round(myangle./gran_theta),:)=0;
movable(1+round((pi+myangle)./gran_theta),:)=0;
z(1+round((pi+myangle)./gran_theta),:)=0;
end
end

% set up immovable concentric circles
if (m>0)
for a=1:m-1
myrad=radmax-(a-1)*(radmax/(m-1));
movable(:,1+round(myrad./gran_rad))=0;
z(:,1+round(myrad./gran_rad))=0;
end
end

%set up initial z values to smooth
rowstart = 1;

for b=2:length(rad)-1
if (m==0 || movable(2,b)==1)
blockstart = rowstart;
for a=1:length(theta)
if movable(a,b)==1
z(a,b)=blockstart;
else
blockstart=blockstart*-1;
end
end
else
rowstart = rowstart*-1;
end
end

%smooth it out using the numerical Laplacian method, modified for polar
%coordinates, or if you prefer, the polar-modified numerical Laplacian
done=0;
iter=0;
while done==0

Haha, glad it could help, and welcome to Cemetech. As long as you credit me (Christopher Mitchell) with the original coding, you're welcome to use and modify my code as you see fit, as long as it's not for commercial profit. I used a discretized numerical Laplacian, aka the Monte Carlo iterative solution scheme, so it's an approximated solution. I'm not sure if it's perfectly accurate, but I hope I got most of it down properly. The polar coordinate scheme is slightly kludgy, but it's as good as anything else I could find to do the same thing. What's your application?

Alright then! Yeah, I know when to give credits where it's due, plus since I'm in college in montreal we don't normally see that in our year. In University yea, but not in our years of college. So, if I presented something like this, I don't think I can get through without ending with a fail due to plagirism.

Anyways, what do you mean by application? Thanks again for the work though =D

Alright then! Yeah, I know when to give credits where it's due, plus since I'm in college in montreal we don't normally see that in our year. In University yea, but not in our years of college. So, if I presented something like this, I don't think I can get through without ending with a fail due to plagirism.

I'm assuming you're using the European naming scheme where college == high school, and university == college, or are you making the distinction that college == undergraduate work and university == graduate work?

Quote:

Anyways, what do you mean by application? Thanks again for the work though =D

Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.