a3_sol.pdf

# Iv the actual relative error of the solution δ y 1 y

This preview shows pages 2–6. Sign up to view the full content.

iv) the actual relative error of the solution, || Δ y || 1 / || y || 1 . Plot (iii) and (iv) against n on a semilogy plot, with axis labels and a legend. (d) Increasing the number of steps decreases the step size and discretization error for the differential equation. Why can’t we continue to increase the number of steps to reduce error to an abritrary level? Based on (c) what value of n minimizes the actual relative error. Note: Results may vary slightly depending on Matlab/Octave and the approach used to build the banded matrix. a) 1 f u n c t i o n A = beammat ( n ) 2 %BEAMMAT Returns s p a r s e d i a g o n a l nxn matrix f o r Euler - B e r n o u l l i Beam 3 % problem pinned at both ends . 4 5 e = ones (n , 1 ) ; 6 A = s p d i a g s ( [ e - 4 * e 6 * e - 4 * e e ] , [ - 2 , - 1 ,0 ,1 ,2] , n , n ) ; 7 A(1 ,1) = 12; A(1 ,2) = - 6; A(1 ,3) = 4/3; 8 A(n , n ) = - 12; A(n , n - 1) = 6; A(n , n - 2) = 4/3; b & c) 1 % 2 % beam s o l u t i o n 3 % 4 5 L = 1; 6 f = - 100; 7 8 f p r i n t f ( ' % - 10s% - 15s% - 15s% - 15s \ n ' , ' n ' , ' cond . no . ' , ' e r r o r bound ' , ' a c t u a l e r r o r ' ) ; 9 10 N = [ 1 0 0 * ( 1 : 9 ) , 1000 * (1:9) , 10000 * (1:10) ] ' ; 11 f o r i = 1: l e n g t h (N) 12 n = N( i ) ; 13 h = L/n ; 14 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
15 % c r e a t e system and s o l v e 16 A = beammat ( n ) ; 17 b = f * hˆ4 * ones (n , 1 ) ; 18 y = A \ b ; 19 20 % C a l c u l a t e t r u e s o l u t i o n 21 x = ( h : h : L) ' ; 22 y t r u e = ( f /24) * ( x . ˆ 2 ) . * ( L - x ) . ˆ 2 ; 23 24 % C a l c u l a t e e r r o r , cond . no . , and e r r o r bound 25 E( i ) = norm ( y - ytrue , 1 ) /norm ( ytrue , 1 ) ; 26 C( i ) = condest (A) ; 27 B( i ) = C( i ) * eps ; 28 29 f p r i n t f ( ' % - 10d% - 15.5g% - 15.5g% - 15.5g \ n ' ,n ,C( i ) ,B( i ) ,E( i ) ) ; 30 31 % d i s p l a y some s o l u t i o n s 32 i f n==1e2 | | n==1e3 | | n==1e4 | | n==1e5 33 f i g u r e 34 p l o t ( x , y , ' k - ' ) ; 35 hold on 36 p l o t ( x , ytrue , ' k - . ' ) ; 37 legend ( ' Computed s o l n ' , ' True s o l n ' ) ; 38 t i t l e ( s p r i n t f ( ' n=%d ' , n ) ) ; 39 x l a b e l ( ' x ' ) ; 40 y l a b e l ( ' y ' ) ; 41 end 42 end 43 44 % compare e r r o r to bound 45 f i g u r e 46 semilogy (N, E , ' k - ' ) ; 47 hold on ; 48 semilogy (N, B, ' k - . ' ) ; 49 legend ( ' Actual E r r o r ' , ' E r r o r Bound ' , ' l o c a t i o n ' , ' s o u t h e a s t ' ) ; 50 x l a b e l ( ' n ' ) 51 y l a b e l ( ' r e l . e r r o r ' ) ; 3
Output for b) 0 0.2 0.4 0.6 0.8 1 x -0.3 -0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 y n=100 Computed soln True soln (a) 0 0.2 0.4 0.6 0.8 1 x -0.3 -0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 y n=1000 Computed soln True soln (b) 0 0.2 0.4 0.6 0.8 1 x -0.3 -0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 y n=10000 Computed soln True soln (c) 0 0.2 0.4 0.6 0.8 1 x -0.3 -0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 y n=100000 Computed soln True soln (d) Output for (c): n cond. no. error bound actual error 100 4.0308e+06 8.9502e-10 0.11538 200 6.7822e+07 1.5059e-08 0.053664 300 3.4862e+08 7.741e-08 0.034937 400 1.1099e+09 2.4646e-07 0.025895 500 2.7215e+09 6.043e-07 0.02057 600 5.6593e+09 1.2566e-06 0.017061 700 1.0506e+10 2.3327e-06 0.014575 800 1.7949e+10 3.9855e-06 0.012721 900 2.8784e+10 6.3914e-06 0.011286 1000 4.3912e+10 9.7504e-06 0.010141 2000 7.0548e+11 0.00015665 0.0050349 4

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3000 3.5763e+12 0.00079411 0.0033475 4000 1.1311e+13 0.0025115 0.0025072 5000 2.7625e+13 0.006134 0.0020039 6000 5.7298e+13 0.012723 0.0016692 7000 1.0617e+14 0.023575 0.001436 8000 1.8115e+14 0.040223 0.0012683 9000 2.902e+14 0.064438 0.0011406 10000 4.4237e+14 0.098227 0.0010372 20000 7.0892e+15 1.5741 0.00018922 30000 3.5782e+16 7.9452 0.0008861 40000 1.1214e+17 24.9 0.0019027 50000 2.6917e+17 59.767 0.0019642 60000 5.4146e+17 120.23 0.011453 70000 9.7455e+17 216.39 0.047136 80000 1.6678e+18 370.34 0.1099 90000 2.7702e+18 615.1 0.18051 100000 4.3092e+18 956.83 0.24569 0 2 4 6 8 10 n 10 4 10 -10 10 -8 10 -6 10 -4 10 -2 10 0 10 2 10 4 rel. error Actual Error Error Bound d) Total Error = Discretization Error + Numerical Error in Solving Linear system Condition number grows rapidly as n increases = numerical error in solving the linear system grows. In this case, actual error is minimized near n = 2 × 10 4 .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern