Write a MATLAB script named ubitnamePP1P2m that calculates a

Write a MATLAB script named ubitname_PP1_P2.m that calculates and displays an estimate of pi using a while loop. Write a MATLAB script named ubitname_PP1_P2. m that calculates and displays an estimate of e using a while loop. To accomplish this, you must write a MATLAB function named ubitname_get_fac .m that accepts a non-negative integer, n (n greaterthanorequalto 0) and returns the factorial, n!, of that number using a for loop. The while loop inside your ubitname_PP1_P2.m script must call your ubitname_get_fac.m function (repeatedly) to calculate your estimate of e.

Solution

1)

n=0

pi=0.0

while(true)

pi=pi+((-1^n)/(2*n + 1))

n=n+1

end

pi=4*pi

2)

est_e=0.0

n=1

while(true)

est_e=est_e+(1/(get_fact(n)))

n=n+1

end

disp(est_e)

function e=get_fact(n)

e=1

if(n>0)

for i=1:n+1

e=e*i

end

end

if(n==0)

e=1

else

e=0

end

 Write a MATLAB script named ubitname_PP1_P2.m that calculates and displays an estimate of pi using a while loop. Write a MATLAB script named ubitname_PP1_P2. m

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site