Paste: heat in discrete
Author: | Rex |
Mode: | ml |
Date: | Mon, 14 Sep 2009 02:20:43 |
Plain Text |
% Model of a discrete form of the heat equation
function heat
d=0.1;
num_steps=5;
num_sects=11;
state = zeros(1,num_sects);
function set_state(the_state)
for n=1:num_sects
state(n)=1-n/num_sects;
end
end
function new_sect =step_section(the_state, n)
% ... a b c ..., we are stepping b
if(n==1)
b=the_state(n);
c=the_state(n+1);
new_sect= d*c+(1-2*d)*b;
elseif(n==num_sects)
a=the_state(n-1);
b=the_state(n);
new_sect=(1-2*d)*b+d*a;
else
a=the_state(n-1);
b=the_state(n);
c=the_state(n+1);
new_sect= d*c+(1-2*d)*b+d*a;
end
end
function new_state=step(the_state)
new_state = zeros(1,num_sects);
for x=1:num_sects
new_state(x)=step_section(the_state,x);
end
end
%MAIN FUNCTION HERE
set_state(state)
for k=1:num_steps
state=[state;step(state(k,:))];
end
state
mesh(state);
end
New Annotation