USING MAT LAB CODE The value of pi can be estimated by Squar
USING MAT LAB CODE: The value of pi can be estimated by: Squareroot 6 (sigma^infinity_n = 1/n^2) Write a program(using a loop) that determines the expression. Run the program with n = 100, n = 10000, and n = 1000000. Compare the result with pi. (Use format long.) Growth data of a sunflower plant is given in the following table: The data can be modeled with a function in the form H = C/(1 + Ae^-Bt) (logistic equation), where H is the height, C is a maximum value for H, A and B are constants, and t is the number of weeks. By using the method described in Section 8.2.2, and assuming that C = 254 cm, determine the constants A and B such that the function best fit the data. Use the function to estimate the height in week 6. In one figure, plot the function and the data points.
Solution
THE MATLAB FUNCTION calculatePI.m
function [PI_VAL ] = calculatePI(N)
%CALCULATEPI is a function used to extimate the value of pi using the
%fomula sqrt(6*sum(1/n^2)), n = 1 to N.
format long
PI_VAL = 0; % clearing the variable PI_VAL
for n =1:N
PI_VAL = PI_VAL + 1/(n^2);
end
PI_VAL = sqrt(6*PI_VAL);
end
MATLAB CALLING THE FUNCTION calculatePI.m AND OUTPUTS
>> PI=calculatePI(100)
PI =
3.132076531809105
>> PI=calculatePI(10000)
PI =
3.141497163947215
>> PI=calculatePI(1000000)
PI =
3.141591698660509
>> pi
ans =
3.141592653589793
>>
