Lec2 - Numerical errors & Numerical derivatives...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Numerical errors & Numerical derivatives Understanding & controlling numerical errors in computation
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture 2 2 f B = kx Bungee problem: full (but with linear spring) (,) dv mf y v m a F dt =↔ = (Newton’s 2 nd Law) slack bungee cord mg 2 R f cv = x g f mg = − 2 R f cv = taut/stretched bungee cord L 0 : length of slack cord y y = 0 Add forces for | y| > L 0 y < 0
Background image of page 2
Lecture 2 3 Approximation of derivative (,) dv m fy v dt = Make discrete approximations of derivatives y i +1 t y t i +1 t i y i true slope approx slope t v Δ t t i +1 t i v i +1 v i true slope approx slope 1 ii i y yv t + ⇒= + Δ
Background image of page 3

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

View Full DocumentRight Arrow Icon
Lecture 2 4 Full bungee problem code >> % Solves bungee jumper problem >> function [y,v,t]=BungeeL2(k,c,L0,m,dt,tmax) >> mg=9.8*m; >> n=tmax/dt; >> t=linspace(0,tmax,n+1); >> y=ones(1,length(t)); >> v=ones(1,length(t)); >> y(1)=0.; % initial position = 0 >> v(1)=0.; % initial velocity = 0 >> for i=1:n >> x=abs(y(i))-L0; >> if x<=0 % cord slack >> f=-mg-c*v(i)*abs(v(i)); >> else % cord stretched >> fB=sign(y(i))*k*x; % linear (not fene!) spring >> f=-mg-c*v(i)*abs(v(i))-fB; >> end >> v(i+1)=v(i)+(f/m)*dt; >> y(i+1)=y(i)+v(i)*dt; >> end
Background image of page 4
Lecture 2 5 Running the program >> k=50; % contents of runBungeeL2.m >> c=0.10; >> L0=50.; >> m=50.; >> dt=0.25; >> tmax=20.; >> [y,v,t]=BungeeL2(k,c,L0,m,dt,tmax); >> plot(t,y) >> grid on Oops! Bobbie bounces too high! (violates conservation of energy) y t
Background image of page 5

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

View Full DocumentRight Arrow Icon
Lecture 2 6 Fixing the problem Need to approximate derivative better Use smaller Δ t at the expense of more computer time …or Find better approximation for derivative (preferred approach) This leads to fewer computer steps, faster execution, & more stable solutions We need to understand how approximations work We need to understand sources of error >> dt=0.05
Background image of page 6
Lecture 2 7 Types of error in computation z Round off error Due to fact that computers can only represent a number with finite number of digits e.g., 3.1415926 is not exactly π but it’s the best a computer can do that only resolves 8 digits z Truncation error The error introduced by approximations that numerical methods may employ e.g. 1 1 ii vv dv R dt t t + + =+ remainder R is the error introduced by mathematical approximation of derivative Round off & truncation errors should be small enough that their effects are not important
Background image of page 7

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

View Full DocumentRight Arrow Icon
Lecture 2 8 Accuracy, Precision, and Errors z Accuracy refers to how closely a computed value agrees with true value z Precision refers to how closely computed values agree with each other z Errors: True fractional error (x100 for percentage) Approx. fractional error (x100 for percentage) From iterative solution
Background image of page 8
Lecture 2 9 Trade offs Accuracy Precision Speed vs Want accuracy & precision to be good but not better than needed (so that speed is sacrificed)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/29/2011 for the course CHE 132b taught by Professor Ceweb during the Fall '09 term at UCSB.

Page1 / 34

Lec2 - Numerical errors &amp; Numerical derivatives...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online