3
PHYS 2411 – Fall 13 Homework 4: Some keys due: 09/27/2013 Problem 1 [25 pts]. Write a program that will calculate the electric field from the electric potential of a positively charged conducting sphere of radius R = 0.8 m and charge Q = 0.5 nC = 0.5×10 –9 C. Use that the electric field is, E=–dV/dr, and for the sphere, the electric potential is given as (k=9×10 9 N.m 2 /C 2 ), V=kQ/r=4.5/r [V], r>R (outside) and V=kQ/R=5.625 V, rR (inside). Calculate E using the forward differentiation with step h = 0.02 m at 21 points equally spaced in the interval of r from 0.001 m to 4 m. Plot the electric potential together with the numeric and theoretical electric fields (E th =4.5/r 2 [V/m], outside, and zero inside) vs. r. Does the numeric result agree with the exact one? Keys: The plot of V and E vs. r is shown above. Note that the derivative is calculated at 21 points (r = 0.001, 0.20095, 0.4009,…, 4 [m] with a step of 0.19995 m). The forward difference derivative is given as, derivFD = (fn(x+h) - fn(x))/h, for any function fn(x) (and with h=0.02 m). For this problem fn(x)is defined by the electric potential inside and outside of the ball (see the function below; note that everything specific to the electric potential V is provided in this function rather than the place where the derivative is calculated). Problem 2 [25 pts]. (No program is required for this problem.) The 4-th degree Legendre polynomial is given as, P 4 (x) = (3–30x 2 +35x 4 )/8. Calculate the absolute approximation error of the forward difference (FD), central difference (CD), and extrapolated difference (ED) algorithms with h = 0.1 for the first derivative of P 4 (x) as a function of x. Keys: The absolute approximation errors are given by h/2*d 2 P 4 (x)/dx 2 for FD, h 2 /2*d 3 P 4 (x)/dx 3 for CD, and h 4 /(64*120)*d 5 P 4 (x)/dx 5 for ED. Hence, there is a quadratic (linear) dependence on x for FD (CD) and no approximation error for ED. Positively charged conducting sphere 0 1 2 3 4 5 6 7 8 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 r [m] V [V] E [V/m], FD E [V/m], exact double fn (double x){ // el. potential of charged conducting ball // k=9E9 N.m 2 /C 2 ; Q=0.5E-9 C if (x>0.8) return ( 4.5/x ); //outside else return ( 5.625 ); //inside }

PHYS2411F13_answersHW4

Embed Size (px)

DESCRIPTION

physics related

Citation preview

Page 1: PHYS2411F13_answersHW4

PHYS 2411 – Fall 13 Homework 4: Some keys due: 09/27/2013

Problem 1 [25 pts]. Write a program that will calculate the electric field from the electric potential of a positively charged conducting sphere of radius R = 0.8 m and charge Q = 0.5 nC = 0.5×10–9C. Use that the electric field is, E=–dV/dr, and for the sphere, the electric potential is given as (k=9×109 N.m2/C2), V=kQ/r=4.5/r [V], r>R (outside) and V=kQ/R=5.625 V, r≤R (inside). Calculate E using the forward differentiation with step h = 0.02 m at 21 points equally spaced in the interval of r from 0.001 m to 4 m. Plot the electric potential together with the numeric and theoretical electric fields (Eth=4.5/r2 [V/m], outside, and zero inside) vs. r. Does the numeric result agree with the exact one?

Keys: The plot of V and E vs. r is shown above. Note that the derivative is calculated at 21 points (r = 0.001, 0.20095, 0.4009,…, 4 [m] with a step of 0.19995 m). The forward difference derivative is given as, derivFD = (fn(x+h) - fn(x))/h, for any function fn(x) (and with h=0.02 m). For this problem fn(x)is defined by the electric potential inside and outside of the ball (see the function below; note that everything specific to the electric potential V is provided in this function rather than the place where the derivative is calculated). Problem 2 [25 pts]. (No program is required for this problem.) The 4-th degree Legendre polynomial is given as, P4(x) = (3–30x2+35x4)/8. Calculate the absolute approximation error of the forward difference (FD), central difference (CD), and extrapolated difference (ED) algorithms with h = 0.1 for the first derivative of P4(x) as a function of x. Keys: The absolute approximation errors are given by h/2*d2P4(x)/dx2 for FD, h2/2*d3P4(x)/dx3 for CD, and h4/(64*120)*d5P4(x)/dx5 for ED. Hence, there is a quadratic (linear) dependence on x for FD (CD) and no approximation error for ED.

Positively charged conducting sphere

0

1

2

3

4

5

6

7

8

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5

r [m]

V [V]

E [V/m], FD

E [V/m], exact

double fn (double x){ // el. potential of charged conducting ball // k=9E9 N.m2/C2; Q=0.5E-9 C if (x>0.8) return ( 4.5/x ); //outside else return ( 5.625 ); //inside }

Page 2: PHYS2411F13_answersHW4

PHYS 2411 – Fall 13 Homework 4: Some keys due: 09/27/2013

Problem 3 [25 pts]. Write a program that will calculate the first derivative of the 4-th degree Legendre polynomial, P4(x) = (3–30x2+35x4)/8, using three differentiation algorithms, forward difference (FD), central difference (CD), and extrapolated difference (ED). Use double data type for floating-point numbers and h = 0.1. The program output should contain, x, P4(x), and the absolute errors for FD, CD, and ED, for 21 points of x equally spaced in the interval, –1 to 1. Make three plots for each of the absolute errors (FD, CD, and ED) as a function of x.

a) Which differentiation method is the most accurate? b) Does the absolute error for ED agree with what you found in Problem 2? c) Does the absolute error for FD follow the dependence on x observed in Problem 2?

Keys: The absolute errors, calculated numerically (numeric derivatives compared to the exact derivatives), and the corresponding analytical approximation errors (as determined in Problem 2) are shown in the plots below. Note that since the approximation error for ED is zero, the plot shows only the roundoff error.

First Derivative

0

0.5

1

1.5

2

2.5

3

-1.5 -1 -0.5 0 0.5 1 1.5

x

Ab

solu

te E

rro

r

FD (numerical)

FD (analytical)

First Derivative

-0.005

0

0.005

0.01

0.015

0.02

0.025

0.03

0.035

0.04

0.045

0.05

-1.5 -1 -0.5 0 0.5 1 1.5

x

Ab

solu

te E

rro

r

CD (numerical)

CD (analytical)

First Derivative

-5.00E-15

0.00E+00

5.00E-15

1.00E-14

1.50E-14

2.00E-14

2.50E-14

3.00E-14

3.50E-14

-1.5 -1 -0.5 0 0.5 1 1.5

x

Abso

lute

Err

or

ED (numerical)

Page 3: PHYS2411F13_answersHW4

PHYS 2411 – Fall 13 Homework 4: Some keys due: 09/27/2013

Problem 4 [25 pts]. (No program is required for this problem.) A high-speed camera (1000 frames/sec and hence, 0.001 s between each frame) is used to calculate the speed of an accelerating object. The distance traveled by the object, as determined at each frame, is recorded in the table below. We want to calculate the speed of the object (v = dx(t)/dt) at time t0 = 0.002 s using the smallest possible step h.

a) What is the minimum step h that could be used with the FD algorithm? b) What is the minimum step h that could be used with the ED algorithm? c) Calculate the speed of the object at time t0 = 0.002 s using the ED algorithm with the step

determined in b). Keys: For FD, the smallest possible step is h=0.001 s. For ED, one needs h/4, which could be at least 0.001 s, and hence h=0.004 s: v! xED

(1) (t0 = 0.002s,h = 0.004s) = 80 m/s. Problem 5 (optional) [25 pts bonus]. Write a program that will read from a file 9 data points for x and f(x) according to the table to the right and calculates the first derivative of f(x) at x = –1, –0.75, –0.5,…, 0.75, 1. Use the forward difference (FD) and central difference (CD) algorithms. Note that the differentiation step h is determined from the x values in the table and will vary for each of the algorithms (choose the smallest possible step for an algorithm). Also note that some of the numeric algorithms may not be applicable to all x points. Print x, FD, and CD derivatives. Make a plot of the numeric derivatives and the exact result, f'(x)=6x2–18x+8 (the first derivative of the function, f(x)=2x3–9x2+8x–5, that fits the data points) vs. x.

t, s 0.000 0.001 0.002 0.003 0.004 0.005 0.006 x, m 0.00 0.02 0.08 0.18 0.32 0.50 0.72

x f(x) –1.00 –24.0000 –0.75 –16.9063 –0.50 –11.5000 –0.25 –7.5938 0.00 –5.0000 0.25 –3.5313 0.50 –3.0000 0.75 –3.2188 1.00 –4.0000