function nma_fem_driver %script to do a simulation of FEM solution of a second order ODE %by Nasser Abbasi %This script calls the m file called nma_fem.m % %this solves the ODE % % a u''(t) + b u'(t) + c u(t) = f(t) % % with t over the range t0 to len % and with initial conditions u(0)=u0 % and with u'(len)=beta % %To use this to solve an ODE, edit the values below for the variables % a,b,c,f,len,u0,x0 close all; clear all; % equation 1. u''+u'+u=sin(x)*cos(x). u(0)=1, u'(len)=beta, len=10 % maxy=4 miny=-1 % a=1, b=1, c=1, x0=0, u0=1,len=10 a=1; b=1; c=1; x0=0; % starting domain point u0=-10; len=10; beta=1; ymax=4; ymin=-2; % for plotting only. To make the plot looks better %This below solves the equation exactly to compare the FEM solution %against. sol= dsolve('a*D2y+b*Dy+c*y=cos(t)*sin(t)','y(0)=-10','Dy(10)=1'); sol=subs(sol); directory='matlab_ANIMATION/'; extension='.png'; MAX_NODES = 100; for n = 3:MAX_NODES ezplot(sol,[0:len,-ymin:ymax]); hold on; r = nma_fem(a,b,c,@f,x0,u0,beta,len,sol,n); %SOLVES by FEM title(sprintf('Solving y''''+y''+y(x)=sin(x)*cos(x). y(0)=1, y''(10)=1. by FEM. \nN=%d\nRMSERROR=%f',n,r)); drawnow; image = getframe(gcf); p=frame2im(image); file_name=[directory num2str(n) extension] ; imwrite(p,file_name,'png'); hold off; % pause(.5) end end %%%%%%%%%%%%%%%%%%%%%%%% % % edit this below to change the forcing function. %%%%%%%%%%%%%%%%%%%%%%%% function v=f(x) v=sin(x).*cos(x); end