Reaction diffusion equation script
25 views (last 30 days)
Show older comments
I need to build a generic script for solving a reaction-diffusion equation of the form-
du/dx = f(u) +D(du/dx)^2
that is based on the explicit Euler method. I have to include the possibility of choosing different boundary conditions.
I have no idea what to do from this point.
The code I have for the Euler method is-
function [U] = Euler(f,y,dt,tmax)
%func - is a function handle
%dt - the steps
%tmax - the maximal time
%y - the first guess
t = dt:dt:tmax;
n = length(t);
U = zeros(length(y),n);
U(:,1) = y;
U_old = y(:);
for i=1:length(t)-1
U_new = U_old+dt.*f(t(i),U_old);
U(:,i+1)=U_new;
U_old=U_new;
end
% grid on;
% plot3(U(1,:),U(2,:),U(3,:),'-b','linewidth');
% title('Solution with Eulers method','fontsize',15);
% xlabel('x','fontsize',18); ylabel('y','fontsize',18); zlabel('z','fontsize',18);
end
3 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!