📄 femerror.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head> <title>Description of femerror</title> <meta name="keywords" content="femerror"> <meta name="description" content=""> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="generator" content="m2html © 2003 Guillaume Flandin"> <meta name="robots" content="index, follow"> <link type="text/css" rel="stylesheet" href="../../m2html.css"></head><body><a name="_top"></a><!-- # AFEM@matlab --><!-- menu.html 2_Solve --><h1>femerror</h1><h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="box"><strong></strong></div><h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="box"><strong>function [l2error, h1error] = femerror(mesh, u, u_x, u_y) </strong></div><h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="fragment"><pre class="comment"> FEMERROR calculates the error of the piecewise linear finite element approximation to the exact solution of a PDE in the L2- and H1-norm. USAGE [l2error] = femerror(mesh, u) [l2error, h1error] = femerror(mesh, u, u_x, u_y) INPUT mesh : current mesh u : exact solution, given as a function u_x,u_y : partial derivatives of the exact solution, given as fct's OUTPUT l2error : error measured in the L2-norm h1error : error measured in the H1-norm</pre></div><!-- crossreference --><h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>This function calls:<ul style="list-style-image:url(../../matlabicon.gif)"></ul>This function is called by:<ul style="list-style-image:url(../../matlabicon.gif)"><li><a href="../../AFEM@matlab/1_Example/Lbig.html" class="code" title="function Lbig">Lbig</a> LBIG solves Poisson equation in a L-shaped domain with FEM with</li><li><a href="../../AFEM@matlab/1_Example/Lshape.html" class="code" title="function Lshape">Lshape</a> LSHAPE solves Poisson equation in a L-shaped domain with FEM with</li><li><a href="../../AFEM@matlab/1_Example/crack.html" class="code" title="function crack">crack</a> CRACK solves Poisson equation in a crack domain with AFEM.</li></ul><!-- crossreference --><h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2><div class="fragment"><pre><a name="_sub0" href="#_subfunctions" class="code">function [l2error, h1error] = femerror(mesh, u, u_x, u_y)</a><span class="comment">%</span><span class="comment">% FEMERROR calculates the error of the piecewise linear finite element</span><span class="comment">% approximation to the exact solution of a PDE in the L2- and H1-norm.</span><span class="comment">%</span><span class="comment">% USAGE</span><span class="comment">% [l2error] = femerror(mesh, u)</span><span class="comment">% [l2error, h1error] = femerror(mesh, u, u_x, u_y)</span><span class="comment">%</span><span class="comment">% INPUT</span><span class="comment">% mesh : current mesh</span><span class="comment">% u : exact solution, given as a function</span><span class="comment">% u_x,u_y : partial derivatives of the exact solution, given as fct's</span><span class="comment">%</span><span class="comment">% OUTPUT</span><span class="comment">% l2error : error measured in the L2-norm</span><span class="comment">% h1error : error measured in the H1-norm</span><span class="comment">%</span><span class="comment">% L. Chen & C. Zhang 10-12-2006</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Check H1-norm needed or not</span><span class="comment">%--------------------------------------------------------------------------</span><span class="keyword">if</span> (nargin < 4 || nargout < 2) isH1 = 0; h1error = 0;<span class="keyword">else</span> isH1 = 1; <span class="keyword">end</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Evaluate u, u_x, u_y at the midpoint of each element</span><span class="comment">%--------------------------------------------------------------------------</span>center = ( mesh.node(mesh.elem(:,1),:)<span class="keyword">...</span> + mesh.node(mesh.elem(:,2),:)<span class="keyword">...</span> + mesh.node(mesh.elem(:,3),:) )/3;u_m = feval(u, center); <span class="comment">% exact solution at the midpoints</span><span class="keyword">if</span> (isH1 == 1) u_x_m = feval(u_x, center); <span class="comment">% x-derivative at the midpoints</span> u_y_m = feval(u_y, center); <span class="comment">% y-derivative at the midpoints</span><span class="keyword">end</span> <span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Evaluate uh, uh_x, uh_y at the midpoint of each element</span><span class="comment">%--------------------------------------------------------------------------</span>edge(:,:,1) = mesh.node(mesh.elem(:,3),:)-mesh.node(mesh.elem(:,2),:);edge(:,:,2) = mesh.node(mesh.elem(:,1),:)-mesh.node(mesh.elem(:,3),:);edge(:,:,3) = mesh.node(mesh.elem(:,2),:)-mesh.node(mesh.elem(:,1),:);area = 0.5*abs(-edge(:,1,3).*edge(:,2,2)+edge(:,2,3).*edge(:,1,2));uh_m = ( mesh.solu(mesh.elem(:,1)) + mesh.solu(mesh.elem(:,2)) <span class="keyword">...</span> + mesh.solu(mesh.elem(:,3)) )/3; <span class="comment">% compute uh at the midpoint</span><span class="keyword">if</span> (isH1 == 1) <span class="comment">% compute gradient of uh if needed</span> uh_x = -( mesh.solu(mesh.elem(:,1)).*edge(:,2,1) <span class="keyword">...</span> + mesh.solu(mesh.elem(:,2)).*edge(:,2,2) <span class="keyword">...</span> + mesh.solu(mesh.elem(:,3)).*edge(:,2,3) )./(2*area); uh_y = ( mesh.solu(mesh.elem(:,1)).*edge(:,1,1) <span class="keyword">...</span> + mesh.solu(mesh.elem(:,2)).*edge(:,1,2) <span class="keyword">...</span> + mesh.solu(mesh.elem(:,3)).*edge(:,1,3) )./(2*area);<span class="keyword">end</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% Midpoint rule for numerical integration</span><span class="comment">%--------------------------------------------------------------------------</span>l2error2 = sum(area.*((u_m - uh_m).^2));l2error = sqrt(l2error2);<span class="keyword">if</span> (isH1 == 1) <span class="comment">% compute H1 error if needed</span> h1error2 = sum(area.*((u_x_m - uh_x).^2 + (u_y_m - uh_y).^2)); h1error = sqrt(l2error2 + h1error2);<span class="keyword">end</span><span class="comment">%--------------------------------------------------------------------------</span><span class="comment">% End of function FEMERROR</span><span class="comment">%--------------------------------------------------------------------------</span></pre></div><hr><address>Generated on Fri 17-Nov-2006 11:02:53 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> © 2003</address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -