<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1524031798287649325</atom:id><lastBuildDate>Sat, 28 Sep 2024 00:59:14 +0000</lastBuildDate><title>One Stop All Solutions</title><description>A single place where you would get almost everything regarding engineering, data mining, data acquisition and IT. Through this blog, I will write articles about numerical and computational techniques, give you short MATLAB codes (occasionally Python or C / C++ too if possible) on diverse fields that I have been involved with (machine learning, Bayesian inference, Genetic Algorithms, Data Acquisition, FEM etc.)</description><link>http://onestopallsolutions.blogspot.com/</link><managingEditor>noreply@blogger.com (Husnain)</managingEditor><generator>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-4495900878331549516</guid><pubDate>Sun, 12 Jun 2011 03:46:00 +0000</pubDate><atom:updated>2011-06-19T06:16:57.473-07:00</atom:updated><title>Latex for Bloggers: Problems &amp; Solutions</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;A few days back a visitor commented that the my equations on this blog are not showing in Google Chrome. It turned out that it was not working in any browser, let alone Google Chrome. I checked out the java script and everything seemed OK. Then I surmised that one of the servers that the script refers to might be down. I checked out and found the following to be not working in the mathtex3.js:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.cyberroadie.org/cgi-bin/mathtex.cgi?&quot;&gt;http://www.cyberroadie.org/cgi-bin/mathtex.cgi?&lt;/a&gt;.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Now one of the solutions could be the replacement of the above server with a valid working server such as the following:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://mathcache.appspot.com/&quot;&gt;http://mathcache.appspot.com/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
But I chose a more simpler solution.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;The Solution&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;The solution was quite simple. I replaced the java script location &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://sites.google.com/site/onestopallsolutions/course-materials/mathtex3.js?attredirects=0&amp;amp;d=1&quot;&gt;https://sites.google.com/site/onestopallsolutions/course-materials/mathtex3.js?attredirects=0&amp;amp;d=1&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
with the working server&#39;s address &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://mathcache.appspot.com/&quot;&gt;http://mathcache.appspot.com/&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
in the java script for latex equations. The final script looked like as shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;source-code&quot;&gt;&amp;lt;script src=&quot;http://mathcache.appspot.com/&quot; type=&quot;text/javascript&quot;&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
onload = function () {
 var els = document.getElementsByTagName(&quot;div&quot;);
 var i = els.length;
 while (i--) {
  if (els[i].className==&quot;latexparse&quot;) {
   replaceMath(els[i]);
  }
 }
};
&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
And now the equations are showing once again.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Setting Up Java Script for Latex in Blogger&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;If you are wondering how to setup a java script for latex in blogger, then you should read the post &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/05/new.html&quot;&gt;Latex for Bloggers: Watchmath not Working &lt;/a&gt;. It explains setting up scripts for latex equations in details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There you go. See you next post.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;ui-datepicker-div&quot; style=&quot;display: none;&quot;&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/06/latex-for-bloggers-problems-solutions.html</link><author>noreply@blogger.com (Husnain)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-6347320812374419692</guid><pubDate>Mon, 23 May 2011 01:04:00 +0000</pubDate><atom:updated>2011-06-08T07:22:46.448-07:00</atom:updated><title>Video Tutorial : How To Implement Finite Element Method 4</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/05/video-tutorial-how-to-implement-finite.html&quot;&gt;previous post&lt;/a&gt; I discussed the procedure for finding out the global stiffness matrix through local elements. In this post we are going to take this process further, develop the entire linear system, elaborate on finding out the force vector and finally solve the system by applying boundary conditions.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Linear System: Ku=F&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;We have already seen how to  formulate the global stiffness matrix. This was one part of the entire linear system which is also called the left hand side. Traditionally, the unknowns are kept on the left hand side and the known values are put on the right hand side. In the animation which follows, the same right hand side has been discussed. This is nothing but the force vector. In all our animations, we have tried to keep things simple by assuming parameters to be constants. The same has been applied in this animation. The objective here is to build an intuition. Complex cases would be addressed later.&lt;br /&gt;
&lt;br /&gt;
Let us now see this animation: &lt;br /&gt;
&lt;a href=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/FifthAnimation.gif&quot;&gt;&lt;img alt=&quot;Photobucket FEM Video Tutorial&quot; border=&quot;0&quot; height=&quot;370&quot; src=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/FifthAnimation.gif&quot; title=&quot;Animated FEM Linear System Development&quot; width=&quot;471&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Solving the System: Boundary Conditions Application&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Once the linear system is developed, the next step is to solve it (of course!). But this step also requires the application of boundary conditions. We will see in what follows that without boundary conditions, the linear system is not resolvable. The matrix is rank deficient and physically this means that the system is not constrained and so any external stimulus may cause it to undergo rigid body motion, however, it will certainly not deform.&lt;br /&gt;
&lt;br /&gt;
Let us now look at the animation below to see how the boundary conditions are applied and how the linear system is resolved.&lt;br /&gt;
&lt;a href=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/sixthanimation.gif&quot;&gt;&lt;img alt=&quot;Photobucket FEM Video Tutorial&quot; border=&quot;0&quot; height=&quot;370&quot; src=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/sixthanimation.gif&quot; title=&quot;Animated FEM Boundary Conditions and System Solution&quot; width=&quot;471&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
In the animation above, we also showed the stresses in the bar, &lt;br /&gt;
&lt;div class=&quot;latexparse&quot;&gt;$$\sigma=E\frac{du}{dx}\ $$ &lt;/div&gt;Since we approximated the deformation by linear functions, therefore, the derivatives of those linear functions would be a constant. The stresses can still be recovered by joining the mid points of the constant slopes over all the elements. &lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Instructions for Viewing the Animations Full Screen&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Here is how to play this animation full screen. Right click and save file as a gif file. If you do not already have storm codec &lt;b style=&quot;color: #660000;&quot;&gt;Media Player Classic&lt;/b&gt; then download it using &lt;a href=&quot;http://download1us.softpedia.com/dl/2e942d150a497e1ca996af290a1250cb/4dc3f1b7/100020053/software/multimedia/video/StormCodec7.exe&quot;&gt;this link&lt;/a&gt;. Open the saved gif file with this media player and play and pause as you like. If you do not play this gif file with media player classic then you can not pause the frames and some frames might be too fast to read properly. This animation could also be played with &lt;b style=&quot;color: #660000;&quot;&gt;Quicktime Player&lt;/b&gt;. You will find it &lt;a href=&quot;http://www.apple.com/quicktime/download/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
See you next post.&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/05/video-tutorial-how-to-implement-finite_22.html</link><author>noreply@blogger.com (Husnain)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-8474224676858266671</guid><pubDate>Tue, 10 May 2011 09:06:00 +0000</pubDate><atom:updated>2011-05-13T15:47:49.491-07:00</atom:updated><title>Video Tutorial : How To Implement Finite Element Method 3</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;From &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/05/tutorial-how-to-implement-finite.html&quot;&gt;this post&lt;/a&gt; we saw how to formulate one row of the stiffness matrix. But this is not how you want the computer to calculate it. In this post we are going to explore, through some animations, how to calculate the entire global stiffness matrix by assembling local or elementary matrices. Please make sure to read the instructions at the end to view the animations full screen and to have play and pause control.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Think Globally Act Locally&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Ultimately you would want to program your approximate solution in some computing language. The first step is to convert the global system (often a large system) into a local framework. This is exactly, think globally act locally kind of a thing. To further elucidate, let me give you another quote:&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;blockquote1&gt; the longest journey begins with a single step&lt;/blockquote1&gt;&lt;/div&gt;Let me further explain the transformation with the help of the following animation:&lt;br /&gt;
&lt;a href=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/second_animation.gif&quot;&gt;&lt;img alt=&quot;Photobucket FEM Video Tutorial&quot; border=&quot;0&quot; height=&quot;280&quot; src=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/second_animation.gif&quot; title=&quot;Animated FEM Element Calculations&quot; width=&quot;471&quot; /&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Element Stiffness Matrix Calculation&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Now that we know how to isolate a single element and what are the elemental conventions, we could calculate the element stiffness matrix. The animation below shows us how:&lt;br /&gt;
&lt;a href=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/third_animation.gif&quot;&gt;&lt;img alt=&quot;Photobucket FEM Video Tutorial&quot; border=&quot;0&quot; height=&quot;290&quot; src=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/third_animation.gif&quot; title=&quot;Animated FEM Element Matrix Calculations&quot; width=&quot;471&quot; /&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;latexparse&quot;&gt;You must have noticed that in order to simplify the calculations, I assumed that $EA(x)=1$. The intuition behind this simplification is the fact that $EA$ is a material property and if that is equal to a constant then the stiffness matrix entries are only dependent upon the shape functions. This makes it easy to think about other problems, without knowing a lot about their physics. For example for the one dimensional electrostatic boundary value problem, the element stiffness matrix is given as:&lt;br /&gt;
$$k_{ij}=\int_{x_{1}^{l}}^{x_{2}^{l}} \varepsilon^{l}(x){N^{l}_{j}}^{\prime}{N^{l}_{i}}^{\prime} dx $$&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;Does it not look similar&lt;/span&gt;&lt;/b&gt;. It sure does. The only difference between the above expression and the one we saw in the animation is that $EA(x)$ is now replaced by the&lt;b&gt;&lt;span style=&quot;color: #274e13;&quot;&gt; permittivity of the medium&lt;/span&gt;&lt;/b&gt; $\varepsilon (x)$, where the former is the product of the &lt;b style=&quot;color: #660000;&quot;&gt;Young&#39;s modulus of elasticity&lt;/b&gt; $E$ and the area of the bar $A$ and the latter is the product of &lt;b&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;dielectric constant&lt;/span&gt;&lt;/b&gt; of the medium $\varepsilon_{r}$ and &lt;b&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;permittivity of the free space&lt;/span&gt;&lt;/b&gt; $\varepsilon_{o}$ ($\varepsilon=\varepsilon_{r}\varepsilon_{o}$). So for a case where $\varepsilon(x)=1$, there is no difference between the element stiffness matrices, provided the element sizes $h^{l}$ are the same.&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Assembling the Element Matrices&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;The next step is to assemble all the local matrices in the global system. The first thing we need for this is the &lt;b style=&quot;color: #660000;&quot;&gt;element connectivity tabl&lt;/b&gt;&lt;b style=&quot;color: #660000;&quot;&gt;e&lt;/b&gt;. An element connectivity table tells us how different elements are connected and which nodes connect which elements. For a one dimensional case, every element is linear and is connected by two nodes on either side. In turn each node connects two elements on either side, except for the first and the last node. To further explain this, the first node connects the first element only, the first element is connected by the first and the second node, and the second node connects the first and the second element. This means that the second node is common to both the first and the second element. Same is true for all the elements until the last element arrives. The last node only connects the last element and that is it.&lt;br /&gt;
&lt;br /&gt;
Once we have the connectivity table, properly identifying the inner nodes and the boundary nodes and all the elements therein, we can move on to assemble the local matrices into a global one. What better way to do that than to show you another small animation.&lt;br /&gt;
&lt;a href=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/fourth_animation-1.gif&quot;&gt;&lt;img alt=&quot;Photobucket FEM Video Tutorial&quot; border=&quot;0&quot; height=&quot;370&quot; src=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/fourth_animation-1.gif&quot; title=&quot;Animated FEM Element Matrix Calculations&quot; width=&quot;471&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Each row has three non zero entries which is coherent with what was said about the global stiffness matrix for a simple one dimensional case with linear elements. However, the first and the last rows contain only two non-zero entries. The reason is that the first and the last nodes connect to one element only.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Instructions for Viewing the Animations Full Screen&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;The instructions to watch the animation are repeated here from &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/05/tutorial-how-to-implement-finite.html&quot;&gt;this post&lt;/a&gt;. Here is how to play this animation full screen. Right click and save file as a gif file. If you do not already have storm codec &lt;b style=&quot;color: #660000;&quot;&gt;Media Player Classic&lt;/b&gt; then download it using &lt;a href=&quot;http://download1us.softpedia.com/dl/2e942d150a497e1ca996af290a1250cb/4dc3f1b7/100020053/software/multimedia/video/StormCodec7.exe&quot;&gt;this link&lt;/a&gt;. Open the saved gif file with this media player and play and pause as you like. If you do not play this gif file with media player classic then you can not pause the frames and some frames might be too fast to read properly. This animation could also be played with &lt;b style=&quot;color: #660000;&quot;&gt;Quicktime Player&lt;/b&gt;. You will find it &lt;a href=&quot;http://www.apple.com/quicktime/download/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
See you next post. &lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/05/video-tutorial-how-to-implement-finite.html</link><author>noreply@blogger.com (Husnain)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-4196020740934497892</guid><pubDate>Sat, 07 May 2011 08:54:00 +0000</pubDate><atom:updated>2011-05-07T08:19:54.289-07:00</atom:updated><title>Latex for Bloggers: Watchmath not Working</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Alright a little diversion. For those of you who have seen previous posts know that I use a lot of latex equations. You can too it is simple.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Writing Latex Equations&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Here are a few simple steps which you could find on a number of blogs. I am sorry if I do not remember those tens of blogs / sites to give them due credits.&lt;br /&gt;
&lt;br /&gt;
1. Go to the design tab of your blogger dashboard.&lt;br /&gt;
&lt;br /&gt;
2. Then click the Page Elements.&lt;br /&gt;
&lt;br /&gt;
3. By default you should have your blog post on the left and some free space on the right (with some default gadgets already included). This should be the layout of your blog page.&lt;br /&gt;
&lt;br /&gt;
4. On the right hand side of your page, click add a gadget. Another window will pop up. Scroll down in this window until you fine HTML/Java Script. Click on the plus sign and it will be added. &lt;br /&gt;
&lt;br /&gt;
5. In the configure HTML/Java Script window copy and paste the following code:&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&quot;source-code&quot;&gt;&amp;lt;script src=&quot;http://www.watchmath.com/cgi-bin/mathtex3.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
replaceMath( document.body );&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
6. Now write your equations as shown below:&lt;br /&gt;
&lt;pre class=&quot;source-code&quot;&gt;$ y=mx+c $
$$ y=\frac{1}{1+e^{x}}\ $$;
&lt;/pre&gt;&lt;br /&gt;
7. The result will be as follows:&lt;br /&gt;
&lt;div class=&quot;latexparse&quot;&gt;$y=mx+c$&lt;br /&gt;
$$y=\frac{1}{1+e^{x}}\ $$&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Watchmath not Working&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Seldom you find out that the site which is hosting the javascript is down. For example the watchmath site which was hosting the latex javascript is down. Click &lt;a href=&quot;http://watchmath.com/vlog/?p=1244&quot;&gt;this link&lt;/a&gt; and you will know. There, however, is a way around. Simply host the script at your site. Simply go to &lt;a href=&quot;http://www.blogger.com/post-edit.g?blogID=1524031798287649325&amp;amp;postID=4196020740934497892&quot;&gt;google sites&lt;/a&gt; and get yourself one for free. And if you do not want to do that, simply copy and paste the following code into the HTML/Java Script gagdet of your blogger and you are done.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;source-code&quot;&gt;&amp;lt;script src=&quot;https://sites.google.com/site/onestopallsolutions/course-materials/mathtex3.js?attredirects=0&amp;amp;d=1&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
replaceMath( document.body );&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Known Issues&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Now, if you know latex, you can easily write beautiful mathematical equations, just by enclosing them between single $ or double $$ signs. But what if you literally want to write the $ sign. The solution to this is proposed by Declan1991 at &lt;a href=&quot;http://www.webdeveloper.com/forum/archive/index.php/t-232018.html&quot;&gt;this site&lt;/a&gt;. Copy and paste the following code instead:&lt;br /&gt;
&lt;pre class=&quot;source-code&quot;&gt;&amp;lt;script src=&quot;https://sites.google.com/site/onestopallsolutions/course-materials/mathtex3.js?attredirects=0&amp;amp;d=1&quot; type=&quot;text/javascript&quot;&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
onload = function () {
 var els = document.getElementsByTagName(&quot;div&quot;);
 var i = els.length;
 while (i--) {
  if (els[i].className==&quot;latexparse&quot;) {
   replaceMath(els[i]);
  }
 }
};
&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Now, whenever you want to write latex equations just enclose your argument between the $ signs as shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;source-code&quot;&gt;&amp;lt; div class=&quot;latexparse&quot;&amp;gt; $your latex argument here$ &amp;lt; /div&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
There you go. See you next post.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/05/new.html</link><author>noreply@blogger.com (Husnain)</author><thr:total>6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-4877802373012208463</guid><pubDate>Fri, 06 May 2011 07:10:00 +0000</pubDate><atom:updated>2011-06-08T07:21:05.669-07:00</atom:updated><title>Video Tutorial : How To Implement Finite Element Method 2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In the  &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/how-to-implement-finite-element.html&quot;&gt;previous post&lt;/a&gt; I discussed some fundamental concepts in implementing the finite element method. In today&#39;s post we will move further. The post ends with a small animation on the calculation of the stiffness matrix.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Stiffness Matrix&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;div class=&quot;latexparse&quot;&gt;For those of you who have a background in engineering, probably know &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;Hooke&#39;s Law&lt;/b&gt;&lt;/span&gt;. It states that the restoring force in the direction opposite and equal to the direction of the applied force is directly proportional to the displacement of the material under the applied load. Mathematically this is stated as:&lt;br /&gt;
&lt;div class=&quot;latexparse&quot;&gt;$f=-ku$&lt;/div&gt;&lt;br /&gt;
The negative sign simply says that the restoring force is in the opposite direction of the applied force. The constant of proportionality $k$ is called the &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;stiffness&lt;/b&gt;&lt;/span&gt; of the material. Its magnitude is easily calculated by:&lt;br /&gt;
$$k=\frac{f}{u}\ $$&lt;br /&gt;
&lt;br /&gt;
Now why are we discussing it here in the context of finite elements. Recall from &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals-cont.html&quot;&gt;this post&lt;/a&gt; that the weak formulation is given by:&lt;br /&gt;
$$ \int_{0}^{l}EA(x) \frac{du}{dx}\ \frac{dv}{dx}\ dx = \int_{0}^{l}f(x)v(x)dx + \left. EA(x) \frac{du}{dx}\ v(x) \right|_{0}^{l}$$&lt;br /&gt;
&lt;br /&gt;
In the  &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals-cont.html&quot;&gt;previous post&lt;/a&gt; we also looked at the formulation of the basis functions and how these basis functions are used in the approximation of finite element method. From the same post let us now write the following:&lt;br /&gt;
$$u(x)=\sum_{j=1}^{n}u_{j}\phi_{j}$$&lt;br /&gt;
$$v(x)=\phi_{i}$$&lt;br /&gt;
&lt;br /&gt;
This substitution is proposed by &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;Galerkin&lt;/b&gt;&lt;/span&gt; and hence this kind of finite element method is also known as &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;Galerkin Finite Element Method&lt;/b&gt;&lt;/span&gt;. Now what is special about this Galerkin method? The special thing about this is that the trial and the test function are defined using the same basis functions. Now remember we were trying to figure out how the term stiffness is involved in finite elements. Let us now substitute the test and the trial functions in the weak form:&lt;br /&gt;
$$ \sum_{j=1}^{n}u_{j}  \int_{0}^{l}EA(x)\frac{d\phi_{j}}{dx}\ \frac{d\phi_{i}}{dx}\ dx= \int_{0}^{l}f(x)\phi_{i}dx $$&lt;br /&gt;
$$+ \left. EA(x) \frac{du}{dx}\ v(x) \right|_{0}^{l}$$&lt;br /&gt;
&lt;br /&gt;
You may notice that we did not replace $u(x)$ in the term $$ \left. EA(x) \frac{du}{dx}\ v(x) \right|_{0}^{l}$$. The reason is that this term is the boundary term and is only calculated at $x=0$ and $x=l$. For an overhanging bar (fixed at one end and free at the other) this term is zero at $x=0$ and is equal to $P\phi_{j}$ at $x=l$, where $P$ is the applied load at the free end. Substituting this results in:&lt;br /&gt;
$$ \sum_{j=1}^{n}u_{j}  \int_{0}^{l}EA(x)\frac{d\phi_{j}}{dx}\ \frac{d\phi_{i}}{dx}\ dx= \int_{0}^{l}f(x)\phi_{i}dx + \left. P \phi_{i} \right|_{x=l}$$&lt;br /&gt;
Writing the above equation in matrix form gives the following:&lt;br /&gt;
$$K_{ij}u_{j}=F_{i}\qquad(a)$$&lt;br /&gt;
Where $$F_{i}=\int_{0}^{l}f(x)\phi_{i}dx + \left. P \phi_{i} \right|_{x=l}$$ is everything on the right hand side and &lt;br /&gt;
$$K_{ij}=\int_{0}^{l}EA(x)\frac{d\phi_{j}}{dx}\ \frac{d\phi_{i}}{dx}\ dx$$. &lt;br /&gt;
&lt;br /&gt;
Now since equation (a) resembles the &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;Hooke&#39;s Law&lt;/b&gt;&lt;/span&gt;, hence the matrix $K$ is called the stiffness matrix. This is the mystery behind calling it the stiffness matrix and it remains as such even if &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;Poisson&#39;s Equation&lt;/b&gt;&lt;/span&gt; is resolved for electric field between two conducting plates.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Stiffness Matrix Calculation&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Let us now see how the stiffness matrix is calculated. This is facilitated with the help of a small animation. The directions to play the animation full screen are given just after.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;blockquote1&gt; Now that we have an expression of the stiffness matrix, let us see a small animation which explains how to calculate it.&lt;/blockquote1&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a href=&quot;http://s1107.photobucket.com/albums/h398/halka_rakh/?action=view&amp;amp;current=animation4.gif&quot;&gt; &lt;img alt=&quot;Photobucket FEM Video Tutorial&quot; border=&quot;0&quot; height=&quot;300&quot; src=&quot;http://i1107.photobucket.com/albums/h398/halka_rakh/animation4.gif&quot; title=&quot;Animated FEM Stiffness Matrix&quot; width=&quot;471&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Here is how to play this animation full screen. Right click and save file as a gif file. If you do not already have storm codec &lt;b style=&quot;color: #660000;&quot;&gt;Media Player Classic&lt;/b&gt; then download it using &lt;a href=&quot;http://download1us.softpedia.com/dl/2e942d150a497e1ca996af290a1250cb/4dc3f1b7/100020053/software/multimedia/video/StormCodec7.exe&quot;&gt;this link&lt;/a&gt;. Open the saved gif file with this media player and play and pause as you like. If you do not play this gif file with media player classic then you can not pause the frames and some frames might be too fast to read properly. This animation could also be played with &lt;b style=&quot;color: #660000;&quot;&gt;Quicktime Player&lt;/b&gt;. You will find it &lt;a href=&quot;http://www.apple.com/quicktime/download/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #073763;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Q1. Why is the second integral zero in the $i-1^{st}$ column?&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;A&lt;/span&gt;.&lt;/span&gt;&lt;/span&gt; The second integral as asked in the animation is zero because the function $\phi_{i+1}$ is zero in the range $x_{i-1}\leq x \leq x_{i}$. Pause at the frame when this question is posed in the animation. You could only pause by playing the gif file in media player classic.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #073763;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Q2. Why is the first integral zero in the $i+1^{st}$ column?&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: #660000;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;A.&lt;/span&gt;&lt;/span&gt; The first integral as asked in the animation is zero because the function $\phi_{i-1}$ is zero in the range $x_{i}\leq x \leq x_{i+1}$. Pause at the frame when this question is posed in the animation. You could only pause by playing the gif file in media player classic.&lt;br /&gt;
&lt;br /&gt;
This is continued until the next post. &lt;/div&gt;&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/05/tutorial-how-to-implement-finite.html</link><author>noreply@blogger.com (Husnain)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-7776216774504574907</guid><pubDate>Mon, 18 Apr 2011 13:27:00 +0000</pubDate><atom:updated>2011-05-07T06:57:42.611-07:00</atom:updated><title>Tutorial : How To Implement Finite Element Method</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals-cont.html&quot;&gt;previous post&lt;/a&gt; I discussed some of the concepts in finite element method. It is important to note that although the case that we have taken up is that of longitudinal deformation of a bar, the findings and discussions are equally applicable to any problem which can be solved by finite element method. Examples of application will be presented later, this post, however deals with the general steps in implementing the method.&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Meshing&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;The first step is to discretize the physical domain into smaller elements. For a one dimensional problem the discretization is very simple, and is shown with the help of Fig. 1 below:&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq7oRIm5nqWQwUSkSd_PboRwW_PeBHKVnftByftpyVmpa8wd7c5tsYbps8isoyjEqWLqtkbfwucIYDqp-fKr4BcUR7FXz4uSc8aGdNcs9imvSo-O2JKGqD-SnIPJVFe_gEdleynMv5Vqqw/s1600/disc1_1_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;262&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq7oRIm5nqWQwUSkSd_PboRwW_PeBHKVnftByftpyVmpa8wd7c5tsYbps8isoyjEqWLqtkbfwucIYDqp-fKr4BcUR7FXz4uSc8aGdNcs9imvSo-O2JKGqD-SnIPJVFe_gEdleynMv5Vqqw/s400/disc1_1_1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Fig. 1&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div class=&quot;latexparse&quot;&gt;The discretization is done by cutting the bar into smaller linear elements. These elements are labelled as $I_{i}$ and the subscript $i$ denotes the element number. Just like the bar, these smaller elements also have end points which are called &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;nodes&lt;/b&gt;&lt;/span&gt; of the elements. These are labelled as $x_{i}$ where the subscript $i$ denotes the node number. The nodes are shown with big dots and they mark the start and end of different elements. Note that the number of elements is one less than the number of nodes. The elements are linear, of course, because the system under consideration is one dimensional. This process of breaking up of the physical domain into smaller pieces is known as &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;meshing&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Basis Functions&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;You may notice that there are coloured triangles over each of the nodes with the exception of the boundary nodes which do not have complete triangles. Moreover, these triangles are labelled as $\phi_{i}$ where $i$ corresponds to the node number. What are these triangles? These triangles are nothing but interpolation functions also called &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;Lagrangian basis functions&lt;/b&gt;&lt;/span&gt;. Their job is to provide a linear approximation of the original solution $u(x)$. This approximation is given as: $$u_{FE}(x)= \sum_{i}u_{i}\phi_{i}(x)$$, where $u_{i}$ is the nodal amplitude.The writing of this equation implies that we are looking for a series solution for the original function $u(x)$.&lt;br /&gt;
&lt;br /&gt;
Let us see through Fig. 2 below, how these basis functions which are also known as &lt;span style=&quot;color: #997755;&quot;&gt;&lt;b&gt;hat functions&lt;/b&gt;&lt;/span&gt; are defined.&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlIMbdCWuvE08393mctym5qxuJSPLZNd5qyEQa8PD42yygHZfhy5B_bd3SySydJJkRR1Pdb3A8ItfumzIDiIFBkUra87Q35MHE-2FPY8VWbQ6nxfeCAEezM6QO9n_PgeSZNtLj0ulb5C5Y/s1600/disc1_2_1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlIMbdCWuvE08393mctym5qxuJSPLZNd5qyEQa8PD42yygHZfhy5B_bd3SySydJJkRR1Pdb3A8ItfumzIDiIFBkUra87Q35MHE-2FPY8VWbQ6nxfeCAEezM6QO9n_PgeSZNtLj0ulb5C5Y/s320/disc1_2_1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Fig. 2&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;A certain basis function $\phi_{i}$ is depicted in Fig. 2. At the nodal coordinate $x_{i}$ to which this basis function belongs, its value should be 1. It can be confirmed from the figure that at $x=x_{i}$ the value of $\phi_{i}$ is 1. Basis functions are defined separately for different segments, as shown in Fig. 2. These functions (hat functions) are non-zero only in the two adjacent elements connecting the node on which they are defined. They are zero everywhere else in the domain.&lt;br /&gt;
&lt;br /&gt;
The topic is continued till the next post.&lt;/div&gt;&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/04/how-to-implement-finite-element.html</link><author>noreply@blogger.com (Husnain)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq7oRIm5nqWQwUSkSd_PboRwW_PeBHKVnftByftpyVmpa8wd7c5tsYbps8isoyjEqWLqtkbfwucIYDqp-fKr4BcUR7FXz4uSc8aGdNcs9imvSo-O2JKGqD-SnIPJVFe_gEdleynMv5Vqqw/s72-c/disc1_1_1.png" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-8603471975062543519</guid><pubDate>Sat, 16 Apr 2011 14:29:00 +0000</pubDate><atom:updated>2011-05-07T06:54:52.100-07:00</atom:updated><title>Tutorial : Finite Element Method Fundamentals Cont...</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals.html&quot;&gt;last post&lt;/a&gt; we had gotten as far as the weak formulation of the problem. We had also posed a few questions. Their answers will be given in this post. The discussion will be general though and applicable to all the problems amenable to finite element approximation.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Weighted Residual!!&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;What is meant by weighted residual? Remember from the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals.html&quot;&gt;previous post&lt;/a&gt;,  the residual of the system were all the terms moved to the left hand  side of the differential equation. The right hand side then had no terms  left and it was obviously equal to zero. In other words, the residual  was equal to zero. If we multiply this residual by some weighing  function, the resultant is still zero (no surprises!). Now the idea of a  weighted residual formulation is to multiply the residual by some  weighing function and then to integrate this product over the entire  domain of the problem. For a one dimensional problem, this is equivalent  to integrating over the length of the domain. The integral is then put  equal to zero. Of course, because the residual is zero.&lt;br /&gt;
&lt;div class=&quot;latexparse&quot;&gt;$$ \int_{\Omega}r(x)w(x)dx=0$$&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Here $\Omega$ is nothing but the physical domain of the problem. For a one dimensional problem and in particular for the problem of longitudinal deformation of a bar, this is the length of the bar.&lt;br /&gt;
&lt;br /&gt;
A very delicate  point in all this process is that since we are approximating a function,  the residual is not strictly equal to zero; owing to approximation  errors. To further elaborate, let us reconsider the expression of the residual function:&lt;br /&gt;
$$r(x)= -\frac{d}{dx}\left ( EA\frac{du}{dx} \right) - f(x)$$&lt;br /&gt;
Since we know that the original function $u(x)$ would be replaced by some finite element trial function $\hat{u}(x)$, which only approximates the original function as close as possible; therefore, there will be a difference in the two solutions and hence the residual is not strictly equal to zero. This brings us to another very important point.&lt;br /&gt;
&lt;div style=&quot;background-color: transparent; color: #997755; text-align: left;&quot;&gt;&lt;b&gt;&quot;Since the residual is not strictly equal to zero, the whole idea of a finite element solution is to find so good an approximation that the residual nearly comes out to be zero and so that the weighted residual integral becomes valid if it is put equal to zero.&quot;   &lt;/b&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Test Function vs Weighing Function&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;In the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals.html&quot;&gt;previous post&lt;/a&gt; I wrote that the weighing function is deliberately omitted and that the test function $v(x)$ is used instead. This point is not a big deal. The weak form of the problem remains the same no matter which of the two are used. The only point worth mentioning here is that somewhere in the history we started using the following convention:&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;$u$ for the trial function&lt;/li&gt;
&lt;li&gt;$v$ for the test function&lt;/li&gt;
&lt;li&gt;$w$ for the weight function&lt;/li&gt;
&lt;/ul&gt;One way of obtaining finite element formulation is to derive the weak form using the weight function $w(x)$ and then substitute for it the test function $v(x)$. When this step is done, it is said that $v(x)$ is an arbitrary admissible function. One key property of this admissible function is that when the original function is supposed to be zero, the test function is also zero. This property comes in handy when applying boundary conditions. See the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals.html&quot;&gt;previous post&lt;/a&gt; for boundary condition application.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Why Call it Weak Form?&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;The next step is to apply integration by parts to the weighted residual formulation or the formulation with the test function, and render the weak form of the integral. Why call it &#39;weak&#39;? It is called a weak form because in the original integral the unknown function is differentiated twice, and the weighing function or the test function is without any differential operator. However, once integration by parts is applied, both the trial and the test functions have the same number of differential operators. &lt;br /&gt;
$$\int_{\Omega} EA(x) \frac{du}{dx}  \frac{dv}{dx} dx = \int_{\Omega}f(x)v(x)dx + \left. EA \left( \frac{du}{dx} \right)  v \right |_{0}^{l}$$&lt;br /&gt;
This process of taking off one differential operator of the original trial function reduces the minimum smoothness criterion. In other words, for the above integral to be finite only the first derivative of the trial function $u(x)$ needs to be defined. If on the other hand we had tried solving the original integral then we would have needed the second derivative of $u(x)$ to be defined also. This is viewed as weakening of the requirement of some higher order derivative to be defined in the integral and hence, this form is called the weak form of the problem. To see the complete steps, refer to my &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals.html&quot;&gt;previous post&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In the next post we will discuss the fundamental steps in realization of finite element approximation.&lt;/div&gt;&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals-cont.html</link><author>noreply@blogger.com (Husnain)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-8268132870011467152</guid><pubDate>Fri, 15 Apr 2011 21:24:00 +0000</pubDate><atom:updated>2011-05-07T06:51:38.716-07:00</atom:updated><title>Tutorial : Finite Element Method Fundamentals</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;hello again,&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;In the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2010/12/simple-1d-finite-elemnt-matlab-code.html&quot;&gt;previous post&lt;/a&gt; I left you guys with a simple code which gives a one dimensional finite element approximation to longitudinal deformation of a bar. Let us learn about the problem in more details.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Problem Definition and its Differential Equation&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;The problem is explained with the help of the following diagram&lt;/div&gt;&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCHy7AMerV56iyF3mvphpFAmSisgITRqG3lF2Z5JK6cpPEASk-xO49kL1RcqsKxlr6eugyQcU0miAhbCBCPdUgly2H_5HCf1S82jzZTz2HvE6JSDXPbDQxm35B9CsT8QpjPg1tH_F-JUub/s1600/Picture1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;132&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCHy7AMerV56iyF3mvphpFAmSisgITRqG3lF2Z5JK6cpPEASk-xO49kL1RcqsKxlr6eugyQcU0miAhbCBCPdUgly2H_5HCf1S82jzZTz2HvE6JSDXPbDQxm35B9CsT8QpjPg1tH_F-JUub/s320/Picture1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Fig. 1&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div class=&quot;latexparse&quot;&gt;As shown in Fig. 1, a bar fixed at one end is subjected to uniform axial force $f_{o}$ and an end load $P$. At the fixed end the deformation $u$ is zero. The objective is to obtain an expression for the deformation $u$ as a function of $x$. To elaborate the implementation of FEM on this simple problem, let us consider its differential equation.&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://www.codecogs.com/eqnedit.php?latex=-%5Cfrac%7Bd%7D%7Bdx%7D%5Cleft%28EA%28x%29%5Cfrac%7Bdu%7D%7Bdx%7D%20%5Cright%20%29-f%28x%29=0&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/gif.latex?-%5Cfrac%7Bd%7D%7Bdx%7D%5Cleft%28EA%28x%29%5Cfrac%7Bdu%7D%7Bdx%7D%20%5Cright%20%29-f%28x%29=0&quot; title=&quot;-\frac{d}{dx}\left(EA(x)\frac{du}{dx} \right )-f(x)=0&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;This equation in terms of the unknown function $u(x)$ is valid in the domain $0 &amp;lt; x&amp;lt; l$ .&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Boundary Conditions Application&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;The boundary conditions given at the two extremities of $x$ are:&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://www.codecogs.com/eqnedit.php?latex=u%28x%29%7C_%7Bx=0%7D=0&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/gif.latex?u%28x%29%7C_%7Bx=0%7D=0&quot; title=&quot;u(x)|_{x=0}=0&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://www.codecogs.com/eqnedit.php?latex=EA%28x%29%5Cleft.%5Cfrac%7Bdu%7D%7Bdx%7D%5Cright%20%7C_%7Bx=l%7D=P&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/gif.latex?EA%28x%29%5Cleft.%5Cfrac%7Bdu%7D%7Bdx%7D%5Cright%20%7C_%7Bx=l%7D=P&quot; title=&quot;EA(x)\left.\frac{du}{dx}\right |_{x=l}=P&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Since the bar is fixed at $x=0$, it is very easy to see that there is no deformation and consequently $u(x)$ is zero at this point. This is called as the &lt;b&gt; &lt;span style=&quot;color: #997755;&quot;&gt; &quot;Dirichlet&quot;&lt;/span&gt;&lt;/b&gt; type of boundary condition. At the other end, no deformation is imposed and consequently the bar is free to deform under the applied load. It can be observed from Fig. 1 that there is an end load present. This end load which is a point force can be expressed in terms of the first derivative of the unknown deformation function $u(x)$. This expression is demonstrated by the second boundary condition and it also goes by the name&lt;b&gt; &lt;span style=&quot;color: #997755;&quot;&gt;&quot;Neumann&quot;&lt;/span&gt;&lt;/b&gt; type of boundary condtion.&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Obtaining the Weak Form&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;The next step is to find the weak form of the differential equation. Let $r(x)$ be the residual of the differential equation given by:&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;$$r(x)=-\frac{d}{dx} \left( EA(x)\frac{du}{dx} \right ) - f(x)$$&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Let us now introduce a test function $v(x)$ which is an admissible function and behaves more or less like the original trial function $u(x)$. Note that we are intentionally skipping the part where the admissible function $v(x)$ is termed as weight function $w(x)$ and multiplied by the residue $r(x)$. This omitted step has the name &quot;weighted residual&quot;. However, we are going to follow almost identical steps as with weighted residual without having to use it explicitly. Since, the residual is zero we may write;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;$$\int_{0}^{l}\left \{ -\frac{d}{dx} \left ( EA (x)\frac{du}{dx} \right ) - f(x) \right \} v(x) dx = 0$$&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;The most important step in FEM formulation is the application of integration by parts. Let us apply this technique first and then see why was it necessary. &lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;$$\int_{0}^{l}EA(x)\frac{du}{dx} \frac{dv}{dx} dx = \int_{0}^{l}f(x)v(x) + \left. EA(x)\frac{du}{dx} v(x) \right |_{0}^{l}$$&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;The second term on the right hand side is the boudary term. At $x=0$, $u=0$ and therefore $v$ is also zero. This is one of the assumptions for the test function to be admissible as mentioned earlier. At $x=l$:&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;$$\left. EA(x)\frac{du}{dx} v(x) \right |_{x=l}=\left. Pv(x)\right |_{x=l}$$&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Simplifying and substituting the boundary conditions, the weak form is finally given as:&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;$$\int_{0}^{l}EA(x)\frac{du}{dx} \frac{dv}{dx} dx = \int_{0}^{l}f(x)v(x) +\left. Pv(x)\right |_{x=l}$$&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;This topic is continued until the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals-cont.html&quot;&gt;next post&lt;/a&gt;. Till then take care.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals.html</link><author>noreply@blogger.com (Husnain)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCHy7AMerV56iyF3mvphpFAmSisgITRqG3lF2Z5JK6cpPEASk-xO49kL1RcqsKxlr6eugyQcU0miAhbCBCPdUgly2H_5HCf1S82jzZTz2HvE6JSDXPbDQxm35B9CsT8QpjPg1tH_F-JUub/s72-c/Picture1.jpg" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1524031798287649325.post-3152692374517494696</guid><pubDate>Mon, 27 Dec 2010 22:39:00 +0000</pubDate><atom:updated>2011-05-07T06:46:08.228-07:00</atom:updated><title>Tutorial : 1D Finite Element Method Matlab Code</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Hello Everybody,&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
This is my first post. What better way to do this than to elaborate the title of my blog. I must confess, I had a tough time coming up with a suitable title, primarily because my interests are very diverse and there were not too many words which could reflect what this blog is all about. I finally managed to come up with this title ‘One Stop All Solutions’. This implies that this would be a single place where you would get almost everything regarding engineering, data mining, acquisition and IT. I know this is exaggerated, but this is what it literally means. &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
On a more practical note, this blog is about my professional experience in the industry, my passion for IT and my recent affair with data mining.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;I have done my PHD in vibrations and acoustics. I taught too while I was doing my PHD and I love sharing knowledge in general, so, through this blog, I will write articles about numerical and computational techniques, give you short MATLAB codes (occasionally Python or C / C++ too if possible) on diverse fields that I have been involved with (machine learning, Bayesian inference, Genetic Algorithms, Data Acquisition, FEM etc.) and not too often I will bore you with anecdotes of my life too, before they are eternally buried in the sands of time.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To  end my first post, I leave you with a Matlab code for a very simple 1D  FEM problem. I will elaborate on this in the &lt;a href=&quot;http://onestopallsolutions.blogspot.com/2011/04/finite-element-fundamentals.html&quot;&gt;next post&lt;/a&gt;. Till then, take  care.&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; fem_1D&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% This is a simple 1D FEM program. The FEM&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% solution is based on linear elements also called hat functions.The&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% problem addressed is the extension of a bar under the action of applied&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% forces. Use mesh parameters under the heading mesh of this code to change&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% values. For example change the number of nodes to 2 to really see the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% difference between the exact and the FEM solution. In general, change&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% constants the way you like. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;%&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% The second plot of stresses in the bar suggests that for each of the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% finite elements in the bar the solution (that is the slope of the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% extension) is a constant. This is illustrated with the help of horizontal&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% lines. Each line also represents one element. It would be shown in later&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% codes that the slope of the approximate solution (stresses) coincides&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% with the slope of the exact solution exactly at the mid point of the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% element.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% This code is inspired from a manual written by Jack Chessa on FEM&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% implementation in MATLAB.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% Written 26-Dec-2010 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% Author: Husnain Inayat Hussain (husnain.inayat@gmail.com)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% FEM_1D&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% 1. PreProcessor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% 2. Processor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% 3. PostProcessor&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% ----------------&amp;nbsp;&amp;nbsp; PREPROCESSOR&amp;nbsp;&amp;nbsp; -------------------&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% Preprocessor consists of defining the problem, material, elemental&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% discretization, geometry, applied conditions such as forces and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% displacements.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% PROBLEM&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7-wVf1enmh9OrjvMhvZ-5-D2jKh5iCed1APBIVeZuj7RLgFR-bBpHddfZo_t8QZIHFw-kEu2EXrqqQPUvTLs4HphtBwshXuhBJHVLtW4HGjHs6rx0u_qCaQT7UJlLhLBViRnaddBsNb6p/s1600/Picture1.jpg&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;132&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7-wVf1enmh9OrjvMhvZ-5-D2jKh5iCed1APBIVeZuj7RLgFR-bBpHddfZo_t8QZIHFw-kEu2EXrqqQPUvTLs4HphtBwshXuhBJHVLtW4HGjHs6rx0u_qCaQT7UJlLhLBViRnaddBsNb6p/s320/Picture1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;% MATERIAL&lt;/span&gt;&lt;br /&gt;
E = 1; % Young&#39;s Modulus&lt;br /&gt;
A = 1; % Area of the bar&lt;br /&gt;
L = 1; % Length of the bar&lt;br /&gt;
f_o = 1;&lt;br /&gt;
u_o =0;&lt;br /&gt;
P = 10;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% MESH&lt;/span&gt;&lt;br /&gt;
num_nodes = 3;&lt;br /&gt;
num_elems = num_nodes - 1;&lt;br /&gt;
nodes = linspace (0,L,num_nodes);&lt;br /&gt;
elm_cnc = [1:1:num_elems ; 2:1:num_nodes]&#39;;&lt;br /&gt;
h_e = nodes (2) - nodes (1);&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% ----------------&amp;nbsp;&amp;nbsp; PROCESSOR&amp;nbsp;&amp;nbsp; -------------------&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Stiffness Matrix&lt;/span&gt;&lt;br /&gt;
K_e = E*A/h_e * [1 -1;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -1&amp;nbsp; 1];&lt;br /&gt;
K = zeros (num_nodes, num_nodes);&lt;br /&gt;
&lt;br /&gt;
F_e = f_o*h_e/2;&lt;br /&gt;
F = zeros (num_nodes, 1);&lt;br /&gt;
&lt;br /&gt;
for i = 1 : size(elm_cnc,1)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; asm = elm_cnc (i,:);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; K(asm , asm) = K(asm , asm) + K_e;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; F(asm) = F(asm) + F_e;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
F = F - K(:,1) * u_o;&lt;br /&gt;
F (1) = u_o;&lt;br /&gt;
F (end) = F (end) + P;&lt;br /&gt;
&lt;br /&gt;
K(1,:) = 0;&lt;br /&gt;
K(:,1) = 0;&lt;br /&gt;
K(1,1) = 1;&lt;br /&gt;
&lt;br /&gt;
u = K\F;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% ----------------&amp;nbsp;&amp;nbsp; POSTPROCESSOR&amp;nbsp;&amp;nbsp; -------------------&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Plot the displacements and the stressed of the analytical and FEM&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% solutions.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% FEM Solution &amp;amp; Plot&lt;/span&gt;&lt;br /&gt;
plot(nodes, u,&#39;Marker&#39;,&#39;o&#39;,&#39;LineWidth&#39;,1,&#39;LineStyle&#39;,&#39;--&#39;,...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;Color&#39;,[1 0 0],...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;DisplayName&#39;,&#39;FEM&#39;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Analytical Solution &amp;amp; Plot&lt;/span&gt;&lt;br /&gt;
x = linspace(0,L,100);&lt;br /&gt;
u1 = - f_o/(2*E*A)*x.^2 + (P + f_o*L)*x;&lt;br /&gt;
hold&lt;br /&gt;
plot(x, u1,&#39;LineWidth&#39;,1,&#39;DisplayName&#39;,&#39;Analytical&#39;);&lt;br /&gt;
h = legend(&#39;FEM&#39;,&#39;Analytical&#39;,2);&lt;br /&gt;
set(h,&#39;Interpreter&#39;,&#39;none&#39;)&lt;br /&gt;
grid on&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Create title&lt;/span&gt;&lt;br /&gt;
title({&#39;Extension of a Longitudianl Bar&#39;,&#39;Analytical vs.FEM Solution&#39;},...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;FontWeight&#39;,&#39;normal&#39;,...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;FontSize&#39;,12);&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Create xlabel&lt;/span&gt;&lt;br /&gt;
xlabel({&#39;Lenght (m)&#39;},&#39;FontWeight&#39;,&#39;normal&#39;,&#39;FontSize&#39;,11);&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Create ylabel&lt;/span&gt;&lt;br /&gt;
ylabel({&#39;Extension (m)&#39;},&#39;FontWeight&#39;,&#39;normal&#39;,&#39;FontSize&#39;,11);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Plot the stresses of the analytical and FEM solutions&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% FEM Solution &amp;amp; Plot&lt;/span&gt;&lt;br /&gt;
figure&lt;br /&gt;
du = zeros (5,1);&lt;br /&gt;
plot(nan,nan)&lt;br /&gt;
hold&lt;br /&gt;
&lt;br /&gt;
h1 = zeros (size(elm_cnc,1),1);&lt;br /&gt;
&lt;br /&gt;
for i = 1 : size(elm_cnc,1)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; du(i) = (u(i+1) - u (i))/ (nodes(i+1) - nodes(i));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; asm = elm_cnc (i,:);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; h1(i) = plot (nodes(asm), repmat(du(i),1,length(nodes(asm))),...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;Marker&#39;,&#39;o&#39;,&#39;LineWidth&#39;,1,&#39;LineStyle&#39;,&#39;--&#39;,&#39;Color&#39;,[1 0 0],...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;DisplayName&#39;,&#39;FEM&#39;);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Analytical Solution &amp;amp; Plot&lt;/span&gt;&lt;br /&gt;
du1 = - f_o/(E*A)*x + (P + f_o*L);&lt;br /&gt;
h2 = plot (x, du1, &#39;LineWidth&#39;,1,&#39;LineStyle&#39;,&#39;-&#39;,...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;Color&#39;,[0 0 1], &#39;DisplayName&#39;,&#39;Analytical&#39;); &lt;br /&gt;
h = legend([h1(end) h2], &#39;FEM&#39;,&#39;Analytical&#39;, 1);&lt;br /&gt;
set(h,&#39;Interpreter&#39;,&#39;none&#39;)&lt;br /&gt;
grid on&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Create title&lt;/span&gt;&lt;br /&gt;
title({&#39;Stresses in a Longitudianl Bar&#39;,&#39;Analytical vs.FEM Solution&#39;},...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;FontWeight&#39;,&#39;normal&#39;,...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;FontSize&#39;,12);&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Create xlabel&lt;/span&gt;&lt;br /&gt;
xlabel({&#39;Lenght (m)&#39;},&#39;FontWeight&#39;,&#39;normal&#39;,&#39;FontSize&#39;,11);&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #274e13;&quot;&gt;% Create ylabel&lt;/span&gt;&lt;br /&gt;
ylabel({&#39;Stress (N/m^2)&#39;},&#39;FontWeight&#39;,&#39;normal&#39;,&#39;FontSize&#39;,11);&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://onestopallsolutions.blogspot.com/2010/12/simple-1d-finite-elemnt-matlab-code.html</link><author>noreply@blogger.com (Husnain)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7-wVf1enmh9OrjvMhvZ-5-D2jKh5iCed1APBIVeZuj7RLgFR-bBpHddfZo_t8QZIHFw-kEu2EXrqqQPUvTLs4HphtBwshXuhBJHVLtW4HGjHs6rx0u_qCaQT7UJlLhLBViRnaddBsNb6p/s72-c/Picture1.jpg" height="72" width="72"/><thr:total>4</thr:total></item></channel></rss>