- Use the Matlab function, integral(·) to numerically integrate the function, y=x2 −2x−4 from1to5.Youwillhavetocreateafunctionandpassafunction
handle to quad(·). See Attaway 14.5. (Answer = ~4/3)
- Write a function using “for-loops” to integrate the mathematical function in Problem #1 using Rectangular integration. Use “Left-corner” Rectangular Integration. The function should take as inputs, a, b, N and a function handle and output the integrated result. (try N=1000) (Answer = ~4/3)
- Using “for-loops”, integrate the same function in Problem #1 using Trapezoidal integration. Use the same function structure as in Problem #2. (Answer = ~4/3)
- Using “for-loops”, integrate the same function in Problem #1 using Simpson’s 1/3 and 3/8 Rule integration. Use the same function structure as in Problem #2. (try N=100) (Answer = ~4/3)
- Write three different functions using “for-loops” to integrate the Gaussian normal distribution curve from [-σ, σ ], [-2σ, 2σ ], and [-3σ, 3σ ], using Rectangular integration. Perform all three types of Rectangular integration: 1) Left-corner; 2) Midpoint and 3) Right-corner. Use the same function structure as in Problem #2. Let μ be 0 and let σ be 1. (try N=1000)
(Answer = ~68.2%,~95.4%,~99.7%)
2 1 1x−μ
y= exp− σ2π 2σ
- Using “for-loops”, integrate the Gaussian function in Problem #5 using Trapezoidal integration. Use the same function structure as in Problem #2.
- Using “for-loops”, integrate the same function in Problem #5 using Simpson’s 1/3 and 3/8 Rule integration. Use the same function structure as in Problem #2. (try N=100)
- Write a function using “for-loops” to integrate the 2-dimensional Gaussian normal distribution curve from [-σ,σ]for both x and y using “Midpoint” Rectangular integration. Use the same function structure as in Problem #2. Use variablesbutletρ,μx andμy be0andletσx andσy be1.Youmayhavetomake the dx and dy values smaller to obtain accurate answers. (try N~3000)
(Answer = ~46.6%)
(y−μ ) 2ρ(x−μ )(y−μ ) f(x,y)= exp−x+y−xy
2
2
1 1(x−μ)
2πσσ1−ρx y xy
2 2(1−ρ2) σ2 σ2 xy
- Use the Matlab function, integral2(·) to numerically integrate the 2D function given in Problem #8 integrating from [–2σ, 2σ ] and integrating from [-3σ, 3σ ] for both x and y. (Answer = ~91.1%,~99.46%)
- Write a Matlab function to numerical differentiate a function, y = xsin2 (x) +1. The function signature is function funk_prime=differentiate(funk,x) where funk is the generic function to be differentiated and x ranges from -4 to 3. Plot both y and y’.
EXTRA CREDIT
11. Write a function using “for-loops” to rotate an image of any size. Test your function using ‘cameraman.tif’ as the input image and rotate the image counter-clockwise 30 degrees and display the result. (HINT: Use inverse mapping by looping over the output pixels and calculating the rotated pixel position in the input image, you can use either nearest-neighbor or bilinear interpolation)