Challenge

Week 2 Challenge- MATLAB Module for an Element Stiffness Matrix

1) Write a matlab function module to accept the input information to calculate stiffness matrix.
The function must accept the following


a) Node coordinates as a vector
b) Must accept material properties E,A,Fy
c) Must return error message if improper arguments are given to function


Node vector must clearly mention the order in which ordinates should be given as input

Ans :-

 function[node_xy,elements,E,A]= input_take()
prompt_1='Enter the node coordinates';
disp('input are [node_x1 node_y1, node_x2 node_y2;....;node_xn,node_yn]');
node_xy=input(prompt_1);

prompt_2='Enter the node connectivity';
disp('input are [node1 node2, node2 node_3;....;node_n-1 node_n]');
elements=input(prompt_2);

prompt_3='Enter the youngs modulus value';
E=input(prompt_3);

prompt_4='Enter the cross section area';
A=input(prompt_4);

fprintf('Value of youngs modulus is = %.4fn',E)
fprintf('Value of cross section area is = %.4fn',A)
end

First we are creating programme which accept the input information like node coordinates, node connectivity, Youngs modulus value and area of cross section.

Explanation for the codes -

function - to create function with given user input to make program more simple.

propmt - it displays the text and waits for user to input a values and with enter key next prompt comes up with expected result.

disp - to display the syntax .

fprintf - this command displays formatted text centered to the screen for the user to view.

end - to end the function.

2) Using node vector from function 1 as input develop a matlab function to calculate the length and orientation φ for each element and save the result to a defined matrix vector. The function must accept node vector of specified element as the input and calculate length and orientation for the element specified

Ans :-

 function[node_xy,length_element,c,s,E,A]=stiff_element_fun()
[node_xy,elements,E,A]= input_take();
node_x=node_xy(:,1);
node_y=node_xy(:,2);

x_co=node_x(2,1)-node_x(1,1);
y_co=node_y(2,1)-node_y(1,1);

length_element=sqrt(x_co*x_co+y_co*y_co)

c=x_co/length_element;
s=y_co/length_element;
end

We will create progamme which will take function one as input and calulate the length and orientation for element .

Explanation for the codes -

function - to create function for given inputs.

[node_xy,elements,E,A] = input_take() - to take input from the previous funtion.

node_x and node_y - to take values of column 1 and 2 resp.

x_co and y_co - to calculate difference between coordinates in the nodes to calculate.

length_element - to calculate the length element using appropriate equation.

c and s - to calculate values for further matrix values.

end - to end the function.

3) Using outputs of function 1 and function 2 develop a matlab function to compute element stiffness matrix and display the output for each element considered. The function must accept material properties E, A as the input from function 1 and length and orientation from function 2 and calculate stiffness matrix for the element specified

Ans :-

 function[stiffness] = solution2()
[node_xy,length_element,c,s,E,A]=stiff_element_fun();
%k1 = zeros(size(node_xy,1));
stiffness=((E*A)/length_element)*[c*c c*s -c*c -c*s; c*s s*s -c*s -s*s;
    -c*c -c*s c*c c*s; -c*s -s*s c*s s*s]
%stiffness=stiffness+k1
end

We have to create function which will take outputs of above two functions and compute the element stiffness matrix with material properties, E, A, lenth and orientation as input .

Explanation of code -

function - to create function with given inputs.

[node_xy,lenght_element,c,s,E,A] = stiff_element_fun - to take inputs of previous funtion.

sitffness - to calculate the stiffness for axial stiffness matrix.

end - to end the function.

4) Use the function from problem 3 and input individual node vectors for each element and calculate individual element stiffness matrix . Based on the concept of concatenation and algorithm discussed in class develop a 6x6 chart for the following problem from each element’s stiffness matrix and arrive at the global stiffness matrix

Ans :-

 function [matrix6by6] = stiffness_matrix_6by6()
[node_xy,elements,E,A] = input_take()
no_nodes = size(node_xy,1);
no_elements=size(elements,1);
dof=2*no_nodes;
matrix6by6=zeros(2*no_nodes);
for e=1:no_elements
    element_nodes= elements(e,1:2);
    node_co=node_xy(element_nodes,:);
    stiffness= solution2();
    element_dof=2*(element_nodes(1)-1)+1:2*(element_nodes(1)-1)+2;
    element_dof=[element_dof 2*(element_nodes(2)-1)+1:2*(element_nodes(2)-1)+2];
    matrix6by6(element_dof,element_dof)=...
        matrix6by6(element_dof,element_dof)+stiffness;
end

Now we have to calculate the individual element stiffness matrix based on concemt of concatenation and algorithm to arrive at the global stiffness matrix.

Explantion of code -

function - to create a function for calculating global stiffness matirx with given inputs as node coordinates, elements, E,A.

size - to calcualte size which will actually give us number of nodes and same for calculateing the number of elements.

zeros - to create zeros matrix with respect to number of nodes.

for - to create loop which will transverse through the number of elements.

element_nodes and node_co - to calculate teh element nodes and node coordinate resp.

stiffness = solution2(); - to call the function into another function.

element_dof - to calculate the degree of freedom using appopriate equation.

matirix6by6 - to perform the concatenation of individual matirces to generate global stiffness matirx.

end - to end the function.

Results :-

input are [node_x1 node_y1, node_x2 node_y2;....;node_xn,node_yn]
Enter the node coordinates [0 0;6.928 4;11 0]
input are [node1 node2, node2 node_3;....;node_n-1 node_n]
Enter the node connectivity [1 2;2 3;3 1]
Enter the youngs modulus value200000
Enter the cross section area1000
Value of youngs modulus is = 200000.0000nValue of cross section area is = 1000.0000n
length_element =

7.9998


stiffness =

1.0e+07 *

1.8750 1.0826 -1.8750 -1.0826
1.0826 0.6250 -1.0826 -0.6250
-1.8750 -1.0826 1.8750 1.0826
-1.0826 -0.6250 1.0826 0.6250

Ans =

1.0e+07 *

2.0837 0.7627 -1.8750 -1.0826 -1.8750 -1.0826
0.7627 0.2792 -1.0826 -0.6250 -1.0826 -0.6250
-1.8750 -1.0826 2.0837 0.7627 -1.8750 -1.0826
-1.0826 -0.6250 0.7627 0.2792 -1.0826 -0.6250
-1.8750 -1.0826 -1.8750 -1.0826 2.0837 0.7627 -1.0826 -0.6250 -1.0826 -0.6250 0.7627 0.2792

Conclusion :-

We created functions which are used to generate a 6by6 global stiffness matrix while generatiing individual stiffness matrix using given inpunts and calculated the length and orientation of elements.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.