{"id":1350,"date":"2021-08-31T07:41:33","date_gmt":"2021-08-31T07:41:33","guid":{"rendered":"https:\/\/people.utm.my\/arazin\/?p=1350"},"modified":"2021-08-31T07:52:49","modified_gmt":"2021-08-31T07:52:49","slug":"1350","status":"publish","type":"post","link":"https:\/\/people.utm.my\/arazin\/2021\/08\/31\/1350\/","title":{"rendered":"FEM Shape Function Generator &#8211; MATLAB CODE"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221;][et_pb_row _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;1_2,1_2&#8243;][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;]<\/p>\n<h2>1D Shape Function<\/h2>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;]<\/p>\n<div class=\"rtcContent\">\n<p>clear, clc<br \/>syms x<br \/>q = 2; %order of poly (eg. quad&#8211;&gt; q=2)<br \/>L = 1;<\/p>\n<p>%create ux = a1 + a2x + &#8230;<br \/>A1 = []; A0 = []; %temporary variables<br \/>ux = 0;<br \/>for i = 1:q+1<br \/>aN = [&#8216;a&#8217; num2str(i)];<br \/>syms(aN);<br \/>ux = ux + aN*x^(i-1);<br \/>A0 = cat(2,A0,[aN,&#8217;,&#8217;]);<br \/>A1 = cat(2,A1,sym(aN));<br \/>end<\/p>\n<p>%use EBC to obtain sufficient simultaneous eqs<br \/>X = 0:L\/q:L;<br \/>for i = 1:length(X)<br \/>eqns(i) = sym(subs(ux,x,X(i)) == [&#8216;u&#8217; num2str(i)]);<br \/>end<\/p>\n<p>%solve the simultaneous eqs<br \/>A2 = solve(eqns,A1);<\/p>\n<p>%convert to ux = Ni*ui<br \/>A3 = expand(subs(ux,A1,struct2array(A2)));<br \/>U1 = []; %temporary variable<br \/>for i = 1:q+1<br \/>uN = [&#8216;u&#8217; num2str(i)];<br \/>syms(uN);<br \/>A3 = collect(A3,uN);<br \/>U1 = cat(2,U1,sym(uN));<br \/>end<\/p>\n<p>%get the SF and their derivative<br \/>SF = coeffs(A3,U1(end:-1:1))<br \/>dSF = diff(SF)<\/p>\n<p>fplot(SF,[0 L])<\/p>\n<\/div>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;]<\/p>\n<h2>2D Shape Function<\/h2>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.2&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; sticky_enabled=&#8221;0&#8243;]<\/p>\n<p>clear, clc<br \/>syms x y E v<br \/>syms a1 a2 a3 a4 T1 T2 T3 T4 real<br \/>a = 1;<br \/>b = 1;<\/p>\n<p>%assumed solution<br \/>Txy = a1 + a2*x + a3*y + a4*x*y;<\/p>\n<p>%obtain equations<br \/>eq1 = subs(Txy,[x y],[0 0]) == T1;<br \/>eq2 = subs(Txy,[x y],[a 0]) == T2;<br \/>eq3 = subs(Txy,[x y],[a b]) == T3;<br \/>eq4 = subs(Txy,[x y],[0 b]) == T4;<\/p>\n<p>%solve simultaneous equations<br \/>A = solve([eq1,eq2,eq3,eq4],a1,a2,a3,a4);<br \/>a1 = A.a1;<br \/>a2 = A.a2;<br \/>a3 = A.a3;<br \/>a4 = A.a4;<\/p>\n<p>%substitute back &amp; rearrange<br \/>Txy = a1 + a2*x + a3*y + a4*x*y;<br \/>Txy = expand(Txy);<br \/>Txy = collect(Txy,[T1,T2,T3,T4])<\/p>\n<p>%determine SF<br \/>[N,Ti] = coeffs(Txy,[T1,T2,T3,T4]);<br \/>N1 = N(1)<br \/>N2 = N(2)<br \/>N3 = N(3)<br \/>N4 = N(4)<\/p>\n<p>fsurf(N1,[0 a 0 b])<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1D Shape Function clear, clcsyms xq = 2; %order of poly (eg. quad&#8211;&gt; q=2)L = 1; %create ux = a1 + a2x + &#8230;A1 = []; A0 = []; %temporary variablesux = 0;for i = 1:q+1aN = [&#8216;a&#8217; num2str(i)];syms(aN);ux = ux + aN*x^(i-1);A0 = cat(2,A0,[aN,&#8217;,&#8217;]);A1 = cat(2,A1,sym(aN));end %use EBC to obtain sufficient simultaneous eqsX = [&hellip;]<\/p>\n","protected":false},"author":6455,"featured_media":1360,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[6,7],"tags":[],"class_list":["post-1350","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fem","category-matlab"],"_links":{"self":[{"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/posts\/1350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/users\/6455"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/comments?post=1350"}],"version-history":[{"count":5,"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/posts\/1350\/revisions"}],"predecessor-version":[{"id":1368,"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/posts\/1350\/revisions\/1368"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/media\/1360"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/media?parent=1350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/categories?post=1350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/people.utm.my\/arazin\/wp-json\/wp\/v2\/tags?post=1350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}