code for problem 9.3 and 9 - purdue.edu · problem 9.3 u_c = 0.250000000000000 0.250000000000000...

5

Upload: dinhdien

Post on 27-Jun-2019

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Code for Problem 9.3 and 9 - purdue.edu · Problem 9.3 u_c = 0.250000000000000 0.250000000000000 0.250000000000000 u_d = 0.125000000000000 0.125000000000000 0.125000000000000 B_x
Page 2: Code for Problem 9.3 and 9 - purdue.edu · Problem 9.3 u_c = 0.250000000000000 0.250000000000000 0.250000000000000 u_d = 0.125000000000000 0.125000000000000 0.125000000000000 B_x
Page 3: Code for Problem 9.3 and 9 - purdue.edu · Problem 9.3 u_c = 0.250000000000000 0.250000000000000 0.250000000000000 u_d = 0.125000000000000 0.125000000000000 0.125000000000000 B_x

Code for Problem 9.3 and 9.4

clear all close all format long

% set number of elements in each segment n=3;u_c=zeros(1,3); u_d=zeros(1,3); B_x=zeros(1,3); E_x=zeros(1,3); Problem = input('For solving: 1) Problem 9.3, 2) Problem 9.4 \n');

for i=1:n %define elemental properties switch Problem case 1 EA=[3*ones(i,1);2*ones(i,1);2*ones(i,1)]; case 2 EA=[3*ones(i,1);2*ones(i,1);2*(0.2/i)*[(5*i+0.5):(6*i-0.5)]']; end L=[1/i*ones(i,1);1/i*ones(i,1);1/i*ones(i,1)];

%set up forcing vector F=zeros(3*i+1,1); F(i+1)=1;

%define boundary conditions BC=zeros(3*i+1,1); BC([1,end])=1; u=zeros(3*i+1,1);

%set up stiffness matrix k=EA./L; K=zeros(3*i+1,3*i+1); for ii=1:3*i K(ii,ii)=K(ii,ii)+k(ii); K(ii+1,ii)=K(ii+1,ii)-k(ii); K(ii,ii+1)=K(ii,ii+1)-k(ii); K(ii+1,ii+1)=K(ii+1,ii+1)+k(ii); end

%enforce BC's on [K] and {F} KK=K;FF=F; for ii=1:3*i+1 jj=3*i-ii+2; if BC(jj)==1 KK(jj,:)=[];KK(:,jj)=[];FF(jj)=[]; end end

%solve u(2:end-1)=inv(KK)*FF; u_c(i)=u(i+1); u_d(i)=u(2*i+1); F=K*u; B_x(i)=F(1); E_x(i)=F(end); end u_c, u_d, B_x, E_x

Page 4: Code for Problem 9.3 and 9 - purdue.edu · Problem 9.3 u_c = 0.250000000000000 0.250000000000000 0.250000000000000 u_d = 0.125000000000000 0.125000000000000 0.125000000000000 B_x

Problem 9.3

u_c =

0.250000000000000 0.250000000000000 0.250000000000000

u_d =

0.125000000000000 0.125000000000000 0.125000000000000

B_x =

-0.750000000000000 -0.750000000000000 -0.750000000000000

E_x =

-0.250000000000000 -0.250000000000000 -0.250000000000000

The columns show the results of using 3, 6, 9 elements respectively.

The results with different number of elements are the same, as well as

the accurate solution in Problem 9.1. This is because the EA’s are

constant, so that the system is linear.

Page 5: Code for Problem 9.3 and 9 - purdue.edu · Problem 9.3 u_c = 0.250000000000000 0.250000000000000 0.250000000000000 u_d = 0.125000000000000 0.125000000000000 0.125000000000000 B_x

Problem 9.4

u_c =

0.247058823529412 0.247121820615796 0.247133596952133

u_d =

0.117647058823529 0.117804551539491 0.117833992380333

B_x =

-0.741176470588235 -0.741365461847390 -0.741400790856400

E_x =

-0.258823529411765 -0.258634538152611 -0.258599209143600

The columns show the results of using 3, 6, 9 elements respectively.

The results change with different number of elements, because EA’s

are not constant, the system is nonlinear. The more elements we have,

the more accuracy we approach.