Skip to content
Permalink
Newer
Older
100644 350 lines (312 sloc) 10.9 KB
Dec 15, 2017
1
Dec 13, 2017
2
# ME3255_Final_Project
Dec 13, 2017
3
4
# Part A
Dec 15, 2017
5
### Problem
Dec 15, 2017
6
Create a central finite difference approximation function to solve for the membrane displacement gradient with 3-by-3 interior nodes '[w]=membrane_solution3(T,P)'. The inputs are tension (T) and pressure (P), and the output is column vector w.
Dec 13, 2017
7
```matlab
8
function [w] = membrane_solution3(T,P)
Dec 15, 2017
9
% membrane_solution3: dispalacement of node for membrane with 3x3 interior
10
% nodes
11
% [w] = membrane_solution3(T,P)
12
% input:
13
% T = Tension (microNewton/micrometer)
14
% P = Pressure (MPa)
15
% output:
16
% w = vector of displacement of interior nodes
Dec 15, 2017
17
18
od = ones(8,1);
19
od(3:3:end) = 0;
20
k = -4*diag(ones(9,1))+diag(ones(9-3,1),3)+diag(ones(9-3,1),-3)+diag(od,1)+diag(od,-1);
21
22
23
y = -(10/4)^2*(P/T)*ones(9,1);
24
w = k\y;
25
26
% Solves for displacement (micrometers)
27
% Solution represents a 2D data set w(x,y)
28
Dec 13, 2017
29
30
[x,y] = meshgrid(0:10/4:10,0:10/4:10);
31
z = zeros(size(x));
32
z(2:end-1,2:end-1) = reshape(w,[3 3]);
33
surf(x,y,z)
Dec 15, 2017
34
title('Membrane Displacement (3 x 3)')
35
zlabel('Z Position (micron)')
36
ylabel('Y Position (micron)')
37
xlabel('X Position (micron)')
38
39
% Membrane displacement is shown on chart
40
41
end
Dec 15, 2017
42
43
end
Dec 13, 2017
44
```
Dec 15, 2017
45
### Approach
46
- A matrix is set up using finite element analysis of the interior nodes of a 5x5 matrix
47
- A vector for the y direction is then set up for the membrane
48
- Using linear algebra, a vector for the displacement of the nodes is created
49
- The vector can then be transformed to represent the actual surface as a matrix
Dec 13, 2017
50
51
# Part B
Dec 15, 2017
52
### Problem
53
Use membranesolution3 function to solve for w and plot the result with surf(X,Y,W). Pressure P=0.001 MPa and tension T=0.006 uN/um.
Dec 13, 2017
54
```matlab
55
% Part B Script
Dec 15, 2017
56
% From problem statement:
57
% T=0.006 uN/um
58
% P=0.001 MPa
Dec 13, 2017
59
[w] = membrane_solution3(0.006,0.001);
60
```
61
![](https://github.uconn.edu/ltd13002/ME3255_Final_Project/blob/master/Part%20B/PartBFigure.png)
62
63
64
# Part C
Dec 15, 2017
65
### Problem
Dec 15, 2017
66
Create a central finite difference approximation function to solve for the membrane displacement gradient with n-by-n interior nodes '[w]=membrane_solution(T,P,n)'. The inputs are tension (T), pressure (P), and number of nodes (n), and the output is column vector w.
Dec 13, 2017
67
```matlab
68
function [w] = membrane_solution(T,P,n)
Dec 15, 2017
69
% membrane_solution: dispalacement of node for membrane with nxn interior nodes
70
% [w] = membrane_solution(T,P,n)
71
% input:
72
% T = Tension (microNewton/micrometer)
73
% P = Pressure (MPa)
74
% n = number of rows and columns of interior nodes
75
% output:
76
% w = vector of displacement of interior nodes
Dec 13, 2017
77
78
od = ones(n^2-1,1);
79
od(n:n:end) = 0;
80
k = -4*diag(ones(n^2,1))+diag(ones((n^2)-n,1),n)+diag(ones((n^2)-n,1),-n)+diag(od,1)+diag(od,-1);
81
82
y = -(10/(n+1))^2*(P/T)*ones(n^2,1);
83
w = k\y;
84
% Solves for displacement (micrometers)
85
% Output w is a vector
86
% Solution represents a 2D data set w(x,y)
87
88
[x,y] = meshgrid(0:10/(n+1):10,0:10/(n+1):10);
89
z = zeros(size(x));
90
z(2:end-1,2:end-1) = reshape(w,[n n]);
91
surf(x,y,z)
Dec 15, 2017
92
title('Membrane Displacement')
93
zlabel('Displacement (micrometer)')
Dec 13, 2017
94
% Membrane displacement is shown on chart
95
end
96
```
Dec 15, 2017
97
### Approach
98
- This problem uses the same steps as with the membrane_solution3 function, except it allows for the user to change the number of interior nodes
99
- This required alterations of the all the indexing and sizing in the function along with a few calculations
Dec 13, 2017
100
101
# Part D
Dec 15, 2017
102
### Problem
103
Use membranesolution function to solve for w and plot the result with surf(X,Y,W). Pressure P=0.001 MPa, tension T=0.006 uN/um, and number of nodes n=10.
Dec 13, 2017
104
```matlab
105
% Part D Script
Dec 15, 2017
106
% From problem statement:
107
% T=0.006 uN/um
108
% P=0.001 MPa
109
% n = 10 nodes
Dec 13, 2017
110
[w] = membrane_solution(0.006,0.001,10)
111
```
112
![](https://github.uconn.edu/ltd13002/ME3255_Final_Project/blob/master/Part%20D/PartDFigure.png)
Dec 13, 2017
113
114
115
# Part E
Dec 15, 2017
116
### Problem
117
Create a function that calculates the difference in strain energy and work done by pressure for n-by-n elements '[pw_se,w]=SE_diff(T,P,n)'.
Dec 13, 2017
118
```matlab
119
function [pw_se,w]=SE_diff(T,P,n)
Dec 15, 2017
120
% SE_diff: calculates difference between strain energy and work done by pressure in
121
% membrane
122
% [pw_se,w]=SE_diff(T,P,n)
123
% input:
124
% T = Tension (microNewton/micrometer)
125
% P = Pressure (MPa)
126
% n = number of rows and columns of interior nodes
127
% output:
128
% pw_se = difference between strain energy and work done by pressure in
129
% membrane
130
% w = vector of displacement of interior nodes
131
Dec 15, 2017
132
E = 1e6; %MPa Units may need to be changed
Dec 13, 2017
133
v = .31; %Poissons ratio
Dec 15, 2017
134
t = .0003; %um
135
h = 10/(n+1); %um
Dec 13, 2017
136
w = membrane_solution(T,P,n);
137
z = zeros(n+2);
138
z(2:end-1,2:end-1) = reshape(w,[n n]);
139
num = n + 1;
140
wbar = zeros(num);
141
for i = 1:num
142
for j = 1:num
143
wbar(i,j) = mean([z(i,j),z(i+1,j),z(i,j+1),z(i+1,j+1)]);
144
end
145
end
146
pw = sum(sum(wbar.*h^2.*P));
147
dwdx = zeros(num);
148
dwdy = zeros(num);
149
for i = 1:num
150
for j = 1:num
151
dwdx(i,j) = mean([z(i+1,j)-z(i,j),z(i+1,j+1)-z(i,j+1)]);
152
dwdy(i,j) = mean([z(i,j+1)-z(i,j),z(i+1,j+1)-z(i+1,j)]);
153
end
154
end
155
se = E*t*h^2/(2*(1-v^2))*sum(sum(0.25.*dwdx.^4+.25.*dwdy.^4+0.5.*(dwdx.*dwdy).^2));
156
pw_se = pw-se;
157
```
Dec 15, 2017
158
### Approach
159
- Using the membrane_solution function, a vector of the displacements is formed
160
- Next, the average displacement for each element is calculated. For each elements, the dispalcement at all four courners is taken and then averaged
161
- Using these values, the work done by pressure can be calculated
162
- For the change in dispalcement over the x and y coordinate system, the values of the change on the left and right (y-axis) or top and bottom (x-axis) are taken and averaged
Dec 15, 2017
163
- Using these values, the strain energy can be calculated
Dec 14, 2017
164
165
# Part F
Dec 15, 2017
166
### Problem
167
Use a root-finding method to calculate the tension in the membrane given a pressure, P=0.001 MPa, and n=[20:5:40] interior nodes. Show the decrease in tension error in a table.
Dec 14, 2017
168
```matlab
Dec 15, 2017
169
% Part F script
170
% From Problem Statement:
Dec 14, 2017
171
n=[3,20:5:40];
172
P=0.001; %MPa
Dec 15, 2017
173
174
% Sets vector length so it doesn't change every iteration in for loop
Dec 14, 2017
175
T = zeros(1,length(n));
176
ea = zeros(1,length(n));
Dec 15, 2017
177
178
% Uses tension_sol function to solve for the tension for each input
Dec 14, 2017
179
for i = 1:length(n)
Dec 14, 2017
180
[T(i), ea(i)] = tension_sol(P,n(i));
Dec 14, 2017
181
end
182
```
183
```matlab
Dec 15, 2017
184
function [T,ea] = tension_sol(P,n)
185
% tension_sol: outputs tension of a membrane given the pressure and number
186
% of nodes
187
% [T,ea] = tension_sol(P,n)
188
% input:
189
% P = Pressure (MPa)
190
% n = number of rows and columns of interior nodes
191
% output:
192
% T = Tension (microNewton/micrometer)
193
% ea = approximate relative error (%)
194
Dec 14, 2017
195
y =@(T) SE_diff(T,P,n);
196
[T,fx,ea,iter]=bisect(y,.01,1);
197
```
198
```matlab
199
function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin)
200
% bisect: root location zeroes
201
% [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,...):
202
% uses bisection method to find the root of func
203
% input:
204
% func = name of function
205
% xl, xu = lower and upper guesses
206
% es = desired relative error (default = 0.0001%)
207
% maxit = maximum allowable iterations (default = 50)
208
% p1,p2,... = additional parameters used by func
209
% output:
210
% root = real root
211
% fx = function value at root
212
% ea = approximate relative error (%)
213
% iter = number of iterations
214
if nargin<3,error('at least 3 input arguments required'),end
215
test = func(xl,varargin{:})*func(xu,varargin{:});
216
if test>0,error('no sign change'),end
217
if nargin<4||isempty(es), es=0.0001;end
218
if nargin<5||isempty(maxit), maxit=50;end
219
iter = 0; xr = xl; ea = 100;
220
while (1)
221
xrold = xr;
222
xr = (xl + xu)/2;
223
iter = iter + 1;
224
if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
225
test = func(xl,varargin{:})*func(xr,varargin{:});
226
if test < 0
227
xu = xr;
228
elseif test > 0
229
xl = xr;
230
else
231
ea = 0;
232
end
233
if ea <= es || iter >= maxit,break,end
234
end
235
root = xr; fx = func(xr, varargin{:});
236
```
237
```matlab
238
function re = Rel_error (T)
Dec 15, 2017
239
Rel_error: calculates relative error of a vector
240
% re = Rel_error (T)
241
% input:
242
% T = vector of numbers
243
% output:
244
% re = relative error of vector
245
Dec 14, 2017
246
re = zeros(1,length(T)-1);
247
for i = 2:length(T)
248
re(i-1)= abs(T(i)-T(i-1))/T(i-1);
249
end
250
```
251
|number of nodes|Tension (uN/um)| rel. error|
252
|---|---|---|
253
|3 |0.0489 |n/a|
254
|20|0.0599|22.6%|
255
|25|0.0601|0.27%|
256
|30|0.0602|0.15%|
257
|35|0.0602|0.09%|
258
|40|0.0603|0.06%|
Dec 14, 2017
259
Dec 15, 2017
260
### Approach
261
- This problem uses the bisect method for locating roots and the SE_diff function for calculating the difference in work and strain energy of the membrane
262
- The script runs through all iterations of different amounts of nodes, zeroing the SE_diff function output and saving the values for tension in the T variable as a vector
Dec 14, 2017
263
# Part G
Dec 15, 2017
264
### Problem
265
Plot the pressure vs maximum deflection for pressure range 0.001-0.01 MPa with 10 steps using a root-finding method to determine tension, T, at each pressure.
Dec 14, 2017
266
```matlab
Dec 15, 2017
267
% Part G Script
268
% From Problem Statement
Dec 14, 2017
269
P = linspace(.001,.01,10);
270
n = 20;
Dec 15, 2017
271
272
% Sets vector length so it doesn't change every iteration in for loop
Dec 14, 2017
273
T = zeros(1,length(P));
274
wmax = zeros(1,length(P));
Dec 15, 2017
275
276
% Uses tension_sol and membrane_solution functions to solve for the maximum displacement for all iterations
Dec 14, 2017
277
for i = 1:length(P)
278
T(i) = tension_sol(P(i),n);
279
w = membrane_solution(T(i),P(i),n);
280
wmax(i) = max(w);
281
end
Dec 15, 2017
282
283
% Sets up figure for plot
Dec 14, 2017
284
clf
285
setDefaults
Dec 15, 2017
286
287
% Standard Linear Regression with equation P(x) = A*w^2
Dec 14, 2017
288
x = wmax';
289
y = P';
290
Z=x.^3;
291
a=Z\y;
292
x_fcn=linspace(min(x),max(x));
Dec 15, 2017
293
294
% Plots regression line with actual points
Dec 14, 2017
295
plot(x,y,'o',x_fcn,a*x_fcn.^3)
Dec 14, 2017
296
title('Pressure vs Maximum Deflection')
297
xlabel('Maximum Deflection (um)')
298
ylabel('Pressure (MPa)')
299
print('Part g','-dpng')
Dec 14, 2017
300
```
Dec 14, 2017
301
![](https://github.uconn.edu/ltd13002/ME3255_Final_Project/blob/master/Part%20G/Part%20g.png)
Dec 15, 2017
302
303
### Approach
304
- This script uses the tension_sol function as described in the part above, running though all iterations of pressure
305
- Additionally, the max deflection for each pressure and tension is calculated at each iteration
306
- From there, a general linear regression is calculated with the formula P(x) = A*w^3
307
- The results are plotted
Dec 15, 2017
308
309
# Part H
Dec 15, 2017
310
### Problem
311
Show that the constant A is converging as the number of nodes is increased.
Dec 15, 2017
312
```matlab
Dec 15, 2017
313
% Part G Script
314
% From Problem Statement
Dec 15, 2017
315
P=0.001;
316
n = 5:5:50;
Dec 15, 2017
317
318
% Sets vector length so it doesn't change every iteration in for loop
Dec 15, 2017
319
a = zeros(1,length(n));
Dec 15, 2017
320
321
% Uses tension_sol and membrane_solution functions along with a regression line to solve for the constant A in the regression line
Dec 15, 2017
322
for i = 1:length(n)
323
T = tension_sol(P,n(i));
324
w = membrane_solution(T,P,n(i));
325
wmax = max(w);
326
x = wmax';
327
y = P';
328
Z = x.^3;
329
a(i) = Z\y;
330
end
Dec 15, 2017
331
332
% Calculates the relative error between the constant A values
Dec 15, 2017
333
Rel_error(a)
334
```
335
|number of nodes|vaalue of const. A| rel. error|
336
|---|---|---|
337
|5 |0.4423 |n/a|
338
|10|0.5389|21.84%|
339
|15|0.5349|0.73%|
340
|20|0.5483|2.5%|
341
|25|0.5454|0.52%|
342
|30|0.5503|0.89%|
343
|35|0.5485|0.31%|
344
|40|0.5510|0.45%|
345
|45|0.5499|0.2%|
346
347
### Approach
348
- Part H uses the same basis as Part G, but with varrying n (number of nodes) valeus instead
349
- Additionally, the outputs and a few calculations were deleted to speed up the process since they were not needed here
350
- In the chart, while there are some fluctuations, there is a clear decrease in the relative error of A, leading to the assumption that it is converging as the number of nodes increases
You can’t perform that action at this time.