0% found this document useful (0 votes)
23 views9 pages

Assignment 3: Shashank Shekhar #50028437

The document is a student's assignment submission for MAE 529 that includes two solutions to a finite element problem. The first solution uses a mesh with uneven node spacing to create a stiffness matrix and plot the results. The second solution changes the basis functions from piecewise linear to piecewise quadratic and develops the corresponding stiffness matrix and plots the results. Comparisons are made between the two solutions and different element numbers.

Uploaded by

tullu29
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views9 pages

Assignment 3: Shashank Shekhar #50028437

The document is a student's assignment submission for MAE 529 that includes two solutions to a finite element problem. The first solution uses a mesh with uneven node spacing to create a stiffness matrix and plot the results. The second solution changes the basis functions from piecewise linear to piecewise quadratic and develops the corresponding stiffness matrix and plots the results. Comparisons are made between the two solutions and different element numbers.

Uploaded by

tullu29
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MAE 529

ASSIGNMENT 3
SHASHANK SHEKHAR
#50028437

Soln 1
For the problem in Case 2 in Assignment 2 create a mesh with unequal spacing i.e. create
nodes spaced unevenly as {0., 0.0001, 0.001, 0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, .0.7, 0.8, 0.9, 0.95,
0.99,0.999,1.}
matlab code
clear all
clc
syms zi;
nele=input('enter the number of elements =');
K=zeros(nele+1);
%stiffness matrix
F=zeros(nele+1,1);
%Force matrix
%input values
for i=1:nele+1;
vnod=input('enter value of the nodes =');
n(i)=vnod*pi;
end
%Transformation matrix.
for i=1:(length(n)-1);
a=[1 n(i);1 n(i+1)];
b=[-1;1];
c=a\b;
%Defining the shape functions
N1=(1-zi)/2;
N2=(1+zi)/2;
N=1-((zi-c(1))/c(2));
w=(zi-c(1))/c(2);

%constructing Stiffness Matrix(N)


k=zeros(2,2);
a1=int(diff(N1)*diff(N1)*(w)^2*c(2),zi,-1,1);
a2=int(N1*N1*(1/c(2)),zi,-1,1)+int(cos(w)*diff(N1)*N1,zi,-1,1);
k(1,1)=a1 + a2;
a11=int(diff(N1)*diff(N2)*(y)^2*c(2),zi,-1,1);
a12=int(N1*N2*(1/c(2)),zi,-1,1)+int(cos(w)*diff(N2)*N1,zi,-1,1);
k(1,2)= a11+ a12;
a21=int(diff(N2)*diff(N1)*(w)^2*c(2),zi,-1,1);
a22=int(N2*N1*(1/c(2)),zi,-1,1)+int(cos(w)*diff(N1)*N2,zi,-1,1);
k(2,1)=a21+a22;
a3=int(diff(N2)*diff(N2)*(w)^2*c(2),zi,-1,1);
a4=int(N2*N2*(1/c(2)),zi,-1,1)+int(cos(w)*diff(N2)*N2,zi,-1,1);
k(2,2)=a3+a4;

% constructing Global stiffness matrix (K)


K(i,i)=K(i,i)+k(1,1);
K(i,i+1)=K(i,i+1)+k(1,2);
K(i+1,i)=K(i+1,i)+k(2,1);
K(i+1,i+1)=K(i+1,i+1)+k(2,2);

% constructing force Matirx


f=zeros(2,1);
f1=int(3*y*N1*1/c(2),zi,-1,1)-(int(diff(N)*diff(N1)*(w)^2*c(2),zi,1,1));
f2=int(N*N1*(1/c(2)),zi,-1,1)+int(cos(y)*diff(N)*N1,zi,-1,1);
f(1,1)=f1+f2;
f21=int(3*y*N2*1/c(2),zi,-1,1)-(int(diff(N)*diff(N2)*(w)^2*c(2),zi,1,1));
f22=int(N*N2*(1/c(2)),zi,-1,1)+int(cos(w)*diff(N)*N2,zi,-1,1);
f(2,1)= f21+f22;
% constructing global Force matrix.
F(i,1)=F(i,1)+f(1,1);
F(i+1,1)=F(i+1,1)+f(2,1);
end

% BC for stiffness matrix.


K(:,1)=0;
K(1,:)=0;
K(1,1)=1;
%BC for Force matrix.
F(1,1)=1;
F(2,1)=F(2,1)-K(2,1);
F(nele+1,1)=2+2*3.14159^2;
%Approximate solution equation
U=K\F;
%Plotting the results.
plot(n,U,'-or')

plot obtained by entering various node value points given in question.

Plot compared with node =10

Plot compared with n=100

Soln 2
Starting with the code you developed in Assignment 2 change the basis functions from
piecewise linear to piecewise quadratic basis functions i.e. use the basis function set

1
N1() ( 1)
2
N2() 1 2
1
N 3() ( 1)
2

Matlab code

clear all
clc
syms z ;
nele=input('Enter the number of elements =');
K= zeros(2*nele+1,2*nele+1);
F= zeros(2*nele+1,1);
for i=1:nele+1
n(i)=(i-1)*pi/(nele);
end
for j= 1:(length(n)-1);
a=[1 n(j); 1 n(j+1)];
b=[-1; 1];
c=a\b;
N1=(z^2-z)/2; N2=(1-z^2); N3=(z^2+z)/2;
diffN1=diff(N1,z);
diffN2=diff(N2,z);
diffN3=diff(N3,z);

k=zeros(3,3);
k(1,1)= int(diffN1*diffN1*c(2),z,-1,1)-int(N1*N1*(1/c(2)),z,-1,1);
k(1,2)= int(diffN1*diffN2*c(2),z,-1,1)-int(N1*N2*(1/c(2)),z,-1,1);
k(1,3)= int(diffN1*diffN3*c(2),z,-1,1)-int(N1*N3*(1/c(2)),z,-1,1);

k(2,1)= int(diffN2*diffN1*c(2),z,-1,1)-int(N2*N1*(1/c(2)),z,-1,1);
k(2,2)= int(diffN2*diffN2*c(2),z,-1,1)-int(N2*N2*(1/c(2)),z,-1,1);
k(2,3)= int(diffN2*diffN3*c(2),z,-1,1)-int(N2*N3*(1/c(2)),z,-1,1);

k(3,1)= int(diffN3*diffN1*c(2),z,-1,1)-int(N3*N1*(1/c(2)),z,-1,1);
k(3,2)= int(diffN3*diffN2*c(2),z,-1,1)-int(N3*N2*(1/c(2)),z,-1,1);
k(3,3)= int(diffN3*diffN3*c(2),z,-1,1)-int(N3*N3*(1/c(2)),z,-1,1);

K(2*j-1,2*j-1)=K(2*j-1,2*j-1)+k(1,1);
K(2*j-1,2*j-1+1)=K(2*j-1,2*j-1+1)+k(1,2);
K(2*j-1,2*j-1+2)=K(2*j-1,2*j-1+2)+k(1,3);
K(2*j-1+1,2*j-1)=K(2*j-1+1,2*j-1)+k(2,1);
K(2*j-1+1,2*j-1+1)=K(2*j-1+1,2*j-1+1)+k(2,2);
K(2*j-1+1,2*j-1+2)=K(2*j-1+1,2*j-1+2)+k(2,3);
K(2*j-1+2,2*j-1)=K(2*j-1+2,2*j-1)+k(3,1);
K(2*j-1+2,2*j-1+1)=K(2*j-1+2,2*j-1+1)+k(3,2);
K(2*j-1+2,2*j-1+2)=K(2*j-1+2,2*j-1+2)+k(3,3);

end
K(:,nele+nele+1)=0;
K(nele+nele+1,:)=0;
K(nele+nele+1,nele+nele+1)=1;
F(nele+nele-1,1)=F(nele+nele-1,1)+k(1,3);
F(nele+nele,1)=F(nele+nele,1)+k(2,3);
F(nele+nele+1,1)=-1;

U=K\F;
nnod=zeros(2*nele+1);
for i=1:2*nele+1
nnod(i)=(i-1)*pi/(2*nele);
end
plot(nnod,U,'g')

Compare your answers from this basis function set and the previous set of just linears for
both linears for the same number of elements.

Plot of comparisons from previous set

You might also like