Вы находитесь на странице: 1из 2

MATLAB Programming for Numerical Computations Jan–March 2018

Assignment for Module–02


Due on: Wednesday, 21st Feb 2018

INSTRUCTIONS

• Submit your work on the course website (https://onlinecourses.nptel.ac.in/noc18_ge05/)


• Please follow all the instructions carefully and submit before the deadline
• Please use MATLAB templates provided for Problems 2 and 4
• You do not need to upload your MATLAB files.

1. A NON-CONVERGENT INFINITE SERIES

All the examples in the course videos have been about convergent series. In this example,
you will code a series that does not converge:
1 1 1
𝑆=1+ + + ⋯+
√2 √3 √𝑛
Write a MATLAB code that takes in the value n and computes the above series sum S.
Please report the value S for various cases, n = 500, 1000, 5000 and 10000.
1–4. Report the values of S for different values of n: 500, 1000, 5000 and 10000Report
the value of x (please report values accurate up to two digits after the decimal)

2. ITERATIVE METHOD FOR CUBE-ROOT

Download the file myCubeRoot.m and use it as a template for this problem.
In the lectures, we saw how to calculate the square root of a number in the iterative
method. In this problem, let us use an iterative algorithm to find +√𝑎 for given value of a. The
formula to find +√𝑎 is given by:
1 𝑎
𝑥-./ = 02𝑥 + 1 2
3 𝑥
The initial guess for starting the code is 𝑥 = 1/2. The iterations stop when absolute error
4𝑥 (-./) − 𝑥4 ≤ tol (where tol is user-supplied). The code also returns number of steps, 𝑛,
required to compute the cube root to the desired tolerance.
5. Call the above function as [res,n]=myCubeRoot(24.0,1e-5). Report the
+
value n, i.e., the number of steps required to find √24 for tolerance of 1e-5.
+
6. Report the number of steps required to find √30 for a tolerance of 1e-7.

1
MATLAB Programming for Numerical Computations Jan–March 2018

3. SMALLEST ERROR FOR DIFFERENTIATION

Use “three-point forward difference formula” for finding 𝑓 < (𝑥 ) for tan@A (𝑥) at 𝑥 = 0.85
−𝑓 (𝑥 + 2ℎ) + 4𝑓 (𝑥 + ℎ) − 3𝑓(𝑥 )
𝑓 < (𝑥 ) =
2ℎ
For value of 𝑥 = 0.85, perform the above for various different values of the step-size
ℎ = [10@1 10@G ⋯ 10@AH ]. For each h, compare with the true value 𝑓 < (𝑥) = (1 + 𝑥 1 )@A
to compute error, err, as absolute difference between the true and approximate values.
7,8. Report value of h at which error is minimum. Also report this minimum err value
(Please report err with three significant digits)

4. MACULARIN SERIES FOR HYPERBOLIC TRIGNOMETRIC FUNCTION

Download the file ml_sinh.m and use it as a template for this problem.
In this problem, you will use MacLaurin Series until the n-th order terms (i.e., terms up
to 𝑥 - ) to compute approximations of hyperbolic sine function, given by:
𝑥G 𝑥N
sinh(𝑥) = 𝑥 + + +⋯
3! 5!
Note that 𝑥 is in radians. In the template file, you will find vector:
𝑥1 𝑥G 𝑥-
vec = R 1 𝑥 … U
2! 3! 𝑛!
pre-computed for you. Please use the vector vec to compute approximate values of sinh(𝑥).
Your function should return sinhVal, while taking the values of x and n as inputs. Report the
following results:
9. Report the results on running: sinhVal=ml_sinh(1,4)
10. Report the error between true value and approximate value calculated from the
function sinhVal, for 𝑥 = 3.0 and 𝑛 = 9WX order term.
(Report the error accurate to four digits after the decimal.)
Note: MATLAB code for finding true value is sinh(x).

Вам также может понравиться