Você está na página 1de 2

AE470 Programming Assignment #1 Wednesday, January 18, 2012 Due on Wednesday, January 25, 2012 Topic: Matlab refresher

r Very important preliminary note: Although you can get help when debugging your codes, all programming assignments must be completed individually. To receive any credit, every code and subroutine must contain the comment line Completed by <enter your name>. Also, every figure that you create should have your name as part of its title (created with the Matlab command title) and clear line style and markers. Special emphasis should be placed in (i) using meaningful variable names and (ii) introducing many comment lines. Your report should contain - A hardcopy of your Matlab code - A hardcopy of the screen output (when requested) - A hardcopy of requested figures (with title, axis labels and curve legends) - Comments on your results (when applicable) Another note: For each problem, some of the new Matlab commands (i.e., those not appearing in previous problems) are listed. Although it is likely that you will use the listed commands, you might be able to do the problem with other Matlab commands. Problem 1. Write a simple Matlab code that receives natural numbers N1 and N2 and computes the following function b X 1 f (N1 , N2 ) = , a = min(N 1, N 2), b = N 1 + N 2 n2 n=a Output the result on the screen as Lower bound of the series a = Upper bound of the series b = Computed function f(N1, N2) = Evaluate the function for (N1, N2) = { (20, 40) , (30, 10) , (10, 100) } Key Matlab commands: input, for, sprintf Problem 2: Write a Matlab code that calculate the number from the following series:
2

16

n=1

Plot the approximation value of for different numbers of the series terms, starting at 1 and up to 20 terms. How many terms of the series are required to reach the precisions of 10-4, 10-8, and 10-12 on the value of ?
Key Matlab commands: plot, title, for, while, xlabel, ylabel, grid, abs

1 X

1 (2n 1)2 (2n + 1)2

Problem 3. Write a simple Matlab code that approximates the function expansion, expressed as follows

1+ x via its Maclaurin series

1+x=

( 1)n (2n)! xn (1 2n)(n!)2 (4n ) n=0

Plot 1+ x and its Maclaurin series expansion with 20 terms for -1<x<1 (use increments of 0.01 for x) on the same plot.

1 X

Given the allowable error tolerance and a value of -1<x<1, compute the number N of terms needed to achieve convergence. Plot the variations of N with at x=0.5 for 10-2<<10-12 (log scale for / linear scale for N). Key Matlab commands: factorial, ylabel, grid, legend for, while, semilogx, title, xlabel,

Problem 4. The finite difference approximation of the first and second derivatives of a functions are described as follow f (x + x) f (x x) f 0 (x) = 2 x

f 00 (x) =

f (x +

x)

2f (x) + f (x x2

x)

where x is a small increment in x. Use above expressions to evaluate the first and second derivatives of the function cos(x)+sin(2x). Plot the exact derivatives and their approximations for -<x< and for x =10-5. Defining the relative error on the first and second derivative as
1(

x, a) = 100 x, a) = 100

0 fexact (a) 00 fexact (a)

0 fnumerical (a, 0 fexact (a) 00 fnumerical (a, 00 fexact (a)

x) x)

2(

calculate the errors on the first and second derivatives at x=0 and display the variation of the errors with x a log-log plot for 10-7<x<10-1. The slope of the resulting curves is defined as the rate of convergence. How does the rate of convergence of the first derivative approximation compares to that of the second derivative? Which derivative is more sensitive to small values of x? Key Matlab commands: plot, logspace, loglog, grid, function.

Você também pode gostar