Integration exercises

From CDS 130

Jump to: navigation, search

1. Area estimation

Using Matlab to estimate the percentage of the area of the shape in the box.


2. Integration

Consider the function  f(x) = 5 \cdot e^{-(x-3)^2} . Write a Matlab program which

  • asks the user to enter values xmin and xmax;
  • (optional) plots this function from xmin to xmax using a logarithmic y-axis;
  • calculates the area under this curve between xmin and xmax.

Note: Use "input" to request user input in MATLAB. see for the documentation of input.

Request a text response. Assign a default value ('Y') by checking for an empty matrix.

  reply = input('Do you want more? Y/N [Y]: ', 's'); 
  if isempty(reply)    
      reply = 'Y'; 

3. Calculation of PI

Suppose you don't know the value of π, but you know the area of a disk (the region inside a circle) is πr2 when the circle has radius r. Design a computational method, and implement the method in Matlab to calculate the value of π based on this information. (For example, you could draw a disk in an image, and calculate the area of the disk.). How accurate is your estimation of π?

Personal tools