Assignment 3: Shashank Shekhar #50028437
Assignment 3: Shashank Shekhar #50028437
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);
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.