"Jordanna De" <jordannad@gmail.com> wrote in message <iat7jm$7mi$1@fred.mathworks.com>...
> I am new to Matlab and have been given the task of deriving pi (ratio of circumference to diameter) using numerical integration. I have done it using the Cartesian coordinates for a semicircle and quad to find the arc length of the unit semicircle. I was told that using parametric equations gives a value closer to the constant used in matlab so I tried that method too. However, my code does not seem to work.
>
> I used angles in degrees to avoid introducing pi. The length formula is the integral of the square root of the sum of the partial derivatives squared.
>
> radius = 1;
> t = linspace(0,360,1000);
> x = radius*cosd(t);
> y = radius*sind(t);
> %plot(x,y);
> %xlabel('x'); ylabel('y'); title('Plot of unit circle');
> Length = quad(@(y) sqrt((radius*sind(y)).^2 + (radius*cosd(y)).^2), 0, 360);
> pi_estimate = Length/(2*radius);
> absolute_error = (ratiopi)/pi;
>
> The code returns a Length of 360 which is the angle subtended instead of the length.
       
Your derivatives are not correct. Remember, the derivative of say the sine of an angle with respect to that angle is only equal to the cosine if you are using radian measure.
However to even be using radian measure already presupposes you already know the ratio between pi and 180. I would think a more convincing way of calculating pi would be some example which has no such assumption, such as the integral of 1/(1+x^2) with respect to x from x = 0 to x = 1. From that integral you can obtain the value of pi and yet there is nothing obviously angular about that function. Archimedes could have used that method if only he had known how to perform numerical integration.
Roger Stafford
