## Drawing Shape Function of Quadratic element (1D) or Beam element

version 1.0.0.0 (1.43 KB) by
This code may help you to draw the shape function in Finite Element Analysis

Updated 01 Dec 2015

% This code can use for ploting shape function of
% Quadratic Element (One Dimensional Problem)
% Beam element
clc; clear all; close all
x_e = 0;
h_e = 1;
Phi_0 = zeros(10,1);
Phi_1 = zeros(10,1);
Phi_2 = zeros(10,1);
Phi_3 = zeros(10,1);
Phi_4 = zeros(10,1);

Case = input('Type 1 for Quadratic Element (1D), Type 2 for Beam Element ');
n = 0;
if Case == 1
for x = 0:.1:1
n = n+1;

phi_1 = (1-(x)/h_e)*(1-(2*x)/h_e);
phi_2 = 4*(x)/h_e*(1-(x)/h_e);
phi_3 = -(x)/h_e*(1-(2*x)/h_e);

Phi_0(:,n) = 0; % This Draws axis line
Phi_1(:,n) = phi_1;
Phi_2(:,n) = phi_2;
Phi_3(:,n) = phi_3;
end

plot (0:.1:1,Phi_1','c')
hold on
plot (0:.1:1,Phi_2','g')
plot (0:.1:1,Phi_3','r')
plot (0:.1:1,Phi_0','k')

else
% Beam element
for x = 0:.1:1
n = n+1;

phi_1 = 1-3*((x-x_e)/h_e).^2+2*((x-x_e)/h_e).^3;
phi_2 = -(x-x_e)*(1-((x-x_e)/h_e)).^2;
phi_3 = 3*((x-x_e)/h_e).^2-2*((x-x_e)/h_e).^3;
phi_4 = -(x-x_e)*(((x-x_e)/h_e).^2-((x-x_e)/h_e));

Phi_0(:,n) = 0; % This Draws axis line
Phi_1(:,n) = phi_1;
Phi_2(:,n) = phi_2;
Phi_3(:,n) = phi_3;
Phi_4(:,n) = phi_4;
end

plot (0:.1:1,Phi_1','c')
hold on
plot (0:.1:1,Phi_2','g')
plot (0:.1:1,Phi_3','r')
plot (0:.1:1,Phi_4','b')
plot (0:.1:1,Phi_0','k') % This Draws axis line
end

### Cite As

Sajeer Modavan (2022). Drawing Shape Function of Quadratic element (1D) or Beam element (https://www.mathworks.com/matlabcentral/fileexchange/54253-drawing-shape-function-of-quadratic-element-1d-or-beam-element), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2007b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux