Write a MATLAB program to perform the integration of a quarter circle.

3 views (last 30 days)
Write a MATLAB program to perform the integration of this quarter circle (radius = 4 units) using the trapezoid method. Since the equation of a circle is x^2+y^2=r^2 , the equation of the quarter-circle as shown is y= sqrt(r^2-x^2) . Calculate the value of pi by dividing the area of the circle (the integral times four) by the radius squared ( ). Your MATLAB program should prompt the user for the number of increments to be used in the integration and should print out the value of pi to five decimal places.
  5 Comments
Meredith Umphlett
Meredith Umphlett on 12 Nov 2019
Yes I am. These are my modifications.
lowlim = 0;
uplim = 4;
r =4;
ni = input('Enter the number of increments');
inc = (uplim-lowlim)/ni;
A = 0;
for k = 1:(ni+1)
x(k) = lowlim + (k-1)*inc;
y(k) = sqrt(16-(x(k)^2));
if k > 1
A = A + .5*(y(k) + y(k-1))*inc;
end
end
% Print the area to the screen
Area = A*4
fprintf('\nThe area is %.5f\n\n',Area)
pie = (Area)/(r^2);
fprintf('\nPie is equal to %.5f\n\n',pie)
Walter Roberson
Walter Roberson on 12 Nov 2019
Is there a reason you are not using trapz() or cumtrapz() ?
x = linspace(lowlim, uplim, ni);
y = sqrt(16-(x.^2));
now caculate the area in vectorized ways

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!