13
Question 1: (a) A can solve 90% of the problems given in a book and B can solve 70%. What is the probability that at least one of them will solve a problem selected at random? Ans 1 p(A cannot solve) = 0.10 P(B cannot solve) = 0.30 Prob(atlest one can solve prob)= 1- P(none can solve problem) = 1 - 0.1x0.3 = 1 - 0.03 = 0.97 = 97% (b) When a computer uses a number base 2, how many significant decimal digits are contained in the mantissa of floating numbers? Ans: Assume that the binary computer has p-bit mantissa. Then the error bound is 2 –p . This computer will have q significant digits with symmetric rounding , if 2 –p = ½ x 10 –q+1  Taking logarithms to the base 10 we get q=1 + (p-1)log 10 2 if we assume p=24 then q=1+23 log 10 2~=7.9 we may say that the computer can store numbers with seven significant decimal digits (c) Evaluate the integral 101dxIx     using (i) composite trapezoidal rule, (ii) composite Simpons rule, with 2, 4 and 8 equal subintervals. Ans: When N=2, we have h=0.5, Nodes are 0, 0.5 and 1 We obtain l  T = ¼ [f(0) + 2f(0.5) + f(1) ] = ¼ [1+ 4/3 + ½] =0.708333 l S = 1/6 [ f(0) + 4f(0.5) + f(1) ] = 1/6 [1+ 8/3 + ½] = 0.694444 N=4 : h = 0.25 , Nodes are 0, 0.25 , 0.5 , 0.75 and 1 . We obtain l  T = 1/8 [ f(0) + 2{f(0.25) +f(0.5) +f(0.75)} +f(1) ] = 0.697024 l S =1/12 [f(0) + 4f(0.25) + 2f(0.5) + 4f(0.75) + f(1) ]

MCSE-004 Solved Assignment 2012-13

Embed Size (px)

Citation preview

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 1/13

Question 1:(a) A can solve 90% of the problems given in a book and B can solve 70%.What is the probability that at least one of them will solve a problemselected at random?Ans 1

p(A cannot solve) = 0.10P(B cannot solve) = 0.30

Prob(atlest one can solve prob)= 1- P(none can solve problem)

= 1 - 0.1x0.3= 1 - 0.03= 0.97= 97%

(b) When a computer uses a number base 2, how many significant decimal

digits are contained in the mantissa of floating numbers?

Ans: Assume that the binary computer has p-bit mantissa. Then the error bound is2 –p . This computer will have q significant digits with symmetric rounding , if 2 –p = ½ x 10 –q+1

 Taking logarithms to the base 10 we getq=1 + (p-1)log 10 2if we assume p=24 thenq=1+23 log 10 2~=7.9we may say that the computer can store numbers with seven significant decimaldigits

(c) Evaluate the integral101dxIx    using (i) composite trapezoidal rule, (ii) composite Simpon‟s rule,with 2, 4 and 8 equal subintervals.Ans:When N=2, we have h=0.5, Nodes are 0, 0.5 and 1We obtain

l T = ¼ [f(0) + 2f(0.5) + f(1) ]= ¼ [1+ 4/3 + ½]=0.708333

lS = 1/6 [ f(0) + 4f(0.5) + f(1) ]= 1/6 [1+ 8/3 + ½]= 0.694444

N=4 : h = 0.25 , Nodes are 0, 0.25 , 0.5 , 0.75 and 1 . We obtain

l T = 1/8 [ f(0) + 2{f(0.25) +f(0.5) +f(0.75)} +f(1) ]= 0.697024

lS=1/12 [f(0) + 4f(0.25) + 2f(0.5) + 4f(0.75) + f(1) ]

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 2/13

= 0.693254

N = 8 : h = 0.125 , nodes are 0, 0.125 , 0.25 , …….1.0We have eight subintervals for trapezoidal rule and four subintervals for Simpson’srule. We getl T = 1/6 [ f(0) + 2Σ7

i=1 f(i/8) + f(1) ]

= 0.694122lS= 1/24 [ f(0) + 4Σ4

i=1 f(2i-1)/8 + 2Σ3i=1 f (2i)/8 + f(1) ]

= 0.693155 The exact value of the integral is I = 0.693147

Question 2: Write the following programme in C language:(a) Write a programme in C to find a root using bisection method.Perform the five iterations of the bisection method to obtain thesmallest positive root of the equation f ( x ) = x 3 – 5 x +1 = 0,verify your answer with the programme written by you.Ans: #include<stdio.h>#include <math.h>#include<conio.h>

#define ESP 0.001#define F(x) (x)*(x)*(x) - 5*(x) + 1

void main(){

int i = 1;float a,b,c;double f1,f2,f0,t;clrscr();

printf("\n Enter the value of a: ");scanf("%f",&a);printf("\n Enter the value of b: ");scanf("%f",&b);printf("\n Accuracy upto %g",ESP);printf("\n________________________________________________________\n");printf("\n n a b c f0 f1 f2");printf("\n________________________________________________________\n");do{

c=(a+b)/2;f0=F(a);

f1=F(b);f2=F©;printf("\n %d %f %f %f %lf %lf %lf", i, a,b,c,f0,f1,f2);getch();if(f0*f2<0){

b=c;}else

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 3/13

{a=c;

}i++;

}while(fabs(f2)>ESP);printf("\n________________________________________________________\n");

printf("\n\nApp.root = %f",c);getch();

}

 

Output a. When ESP=0.01Enter the value of a: 0

Enter the value of b: 1

Accuracy upto 0.01

 _____________________________________________________________________ 

n a b c f0 f1 f2 ______________________________________________________________________ 

1 0.000000 1.000000 0.500000 1.000000 -3.000000 -1.3750002 0.000000 0.500000 0.250000 1.000000 -1.375000 -0.2343753 0.000000 0.250000 0.125000 1.000000 -0.234375 0.3769534 0.125000 0.250000 0.187500 0.376953 -0.234375 0.0690925 0.187500 0.250000 0.218750 0.069092 -0.234375 -0.0832826 0.187500 0.218750 0.203125 0.069092 -0.083282 -0.007244

 _____________________________________________________________________ 

App.root = 0.203125

b) when ESP = 0.001

Enter the value of a: 0

Enter the value of b: 1

Accuracy upto 0.001 _____________________________________________________________________ 

n a b c f0 f1 f2 ______________________________________________________________________ 

1 0.000000 1.000000 0.500000 1.000000 -3.000000 -1.3750002 0.000000 0.500000 0.250000 1.000000 -1.375000 -0.2343753 0.000000 0.250000 0.125000 1.000000 -0.234375 0.3769534 0.125000 0.250000 0.187500 0.376953 -0.234375 0.0690925 0.187500 0.250000 0.218750 0.069092 -0.234375 -0.083282

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 4/13

6 0.187500 0.218750 0.203125 0.069092 -0.083282 -0.0072447 0.187500 0.203125 0.195312 0.069092 -0.007244 0.0308888 0.195312 0.203125 0.199219 0.030888 -0.007244 0.0118139 0.199219 0.203125 0.201172 0.011813 -0.007244 0.00228210 0.201172 0.203125 0.202148 0.002282 -0.007244 -0.00248211 0.201172 0.202148 0.201660 0.002282 -0.002482 -0.000100

 _____________________________________________________________________ App.root = 0.201660

(b) Write a programme in C to find a root using Newton RaphsonMethod. Apply Newton-Raphson‟ s method to determine a root of the equation f (x) = cos x – xex  = 0, if exists verify your answerwith the programme written by you.

 /* Root Using Secant Method*/

#include <stdio.h>

#include <math.h>

#define f(x) (exp(x)*log(x)-x*x)

main()

/* Main program to use the Secant Method to find the root of 

f(x)=exp(x)*ln(x)-x*x=0. Copyright © Tao Pang 1997. */

{

int istep;

double dl=1e-6;

double a,b,xi,xf,di,df;

void secant ();

a = 1; b = 2;

di = (b-a)/10;

xi = (a+b)/2;

secant (dl,xi,di,&xf,&df,&istep);

printf("%4d %16.8lf %16.8lf\n", istep,xf,df);

}

void secant (dl,xi,di,xf,df,istep)

/* Subroutine for the root of f(x)=0 with the secant method.

Copyright © Tao Pang 1997. */

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 5/13

int *istep;

double dl,xi,di;

double *xf,*df;

{

double x0,x1,x2,d;

x0 = xi;

x1 = xi+di;

*df = di;

*istep = 0;

while (fabs(*df) > dl)

{

d = f(x1)-f(x0);

x2 = x1-f(x1)*(x1-x0)/d;

x0 = x1;

x1 = x2;

*df = x1-x0;

*istep = *istep+1;

}

*xf = x0;

}

Question 3:(a) Find the probability of getting between 6 and 9 tails inclusive in20 tosses of a fair coin by using (i) the binomial distribution,(ii) the normal approximation to the binomial distribution.

Ans: (i)

Let us call it a 'success' when tails comes .

 Then , p = 1/2 , q=1/2 and n=20

 Therefore the probability of getting between 6 and 9 tails in 20 tosses are as follows

p(6)+p(7)+p(8)+p(9)= 20 C 6 (1/2)^6 (1/2)^14 +20 C 7 (1/2)^7 (1/2)^13 +20 C 8 (1/2)^8 (1/2)^12

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 6/13

+20 C 9 (1/2)^9 (1/2)^11= fact20/fact6 fact14*64*16384 + fact20/fact7 fact13*128*8192 +

fact20/fact8 fact12*256*4096 + fact20/fact9 fact11*512*2048=4845/131072+77520/1048576+125970/1048576+1175720/1048576=1.3521

(ii)

Here n=20 , p=1/2 , q=1/2σ^2=npq=5σ=2.236μ=np=10We require P[6<X<9]

Using standard normal distribution , we get

p[6-10/2.236<Z<9-10/2.236]=p[-1.78<Z<-0.44]=0.2925

(b) Table 2 below shows the respective heights x and y of a sample of 12 fathers and their oldest sons.(i) Construct a scatter diagram.(ii) Find the least-squares regression line of  y on x .(iii) Find the least-squares regression line of  x and y .Table 2Height xof 

Father(centimetres)

165 160

170 163

173

158 178

168 173 170

175 180

Height yof Son(centimetres)

173 168

173 165

175

168 173

165 180 170

173 178

Ans:From given table we have, ∑x=2033 , Mean(x) =169.42,

∑y=2061, Mean(y) =171.75 , u=x-169, v=y-171

X y u u2 v v2 u*v

165 173 -104 10816 2 4 -208

160 168 -9 81 -3 9 27

170 173 1 1 2 4 2

163 65 -6 36 -6 36 36

173 175 4 16 4 16 16

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 7/13

158 168 -11 121 -3 9 33

178 173 9 81 2 4 18

168 165 -1 1 -6 36 6

173 180 4 16 9 81 36

170 170 1 1 -1 1 -1

175 173 6 36 2 4 12

180 178 11 121 7 49 77

From above table we get,

∑u=-95, ∑v=9, ∑uv=54, ∑u^2=11327, ∑v^2=253

 Therefore,b_yx = ∑uv-1/n ∑u∑v / ∑u^2-(∑u) ^2/n

=1503/126899=0.01

b_xy = ∑uv-1/n ∑u∑v / ∑v^2-(∑v) ^2/n=1503/2955=0.51

 Therefore, the least-square regression line of y on x is:y-171.75=(0.01)(x-169.42)

=≫ y=0.01x+169.31

Regression line of x on y is: x-169.42=(0.51)(y-171.75)=≫ x=0.51y+169.31=≫ x=0.51y+81.83

(c) Find the area under the standard normal curve (a) between z = 0 and z = 1.2,(b) between z = – 0.68 and z = 0, (c) between z = – 0.46 and z = 2.21, (d) betweenz = 0.81and z = 1.94.Ans:(a)

z=0 and z=1.2p (0 ≤ z ≤ 1.2)=F (1.2)-F (0)=.3849 (from normal dist table)

(b)z=-0.68 and z=0p (-0.068 ≤ z ≤ 0)=p (0 ≤z ≤0.068)=F (0.068)-F(0)=0.7517 (from normal dist table)

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 8/13

(c)z=-0.46 and z=2.21p (-0.46 ≤ z ≤ 2.21)=F (2.21)-[1-F (0.46)]=0.9864-0.3228 (from normal dist table)

=0.6636

(d)z=0.81 and z=1.94p (0.81 ≤ z ≤ 1.94)=F (1.94)-F (0.81)=0.9738-0.7910 (from normal dist table)=0.1828

Question 4: Solve the following equation (if a solution exists) using given method:(a) Solve the equation:10 x 1 – x 2 + 2 x 3 = 4

 x 1 + 10 x 2 – x 3 = 32 x 1 + 3 x 2 + 20 x 3 = 7using the Gauss elimination method.Ans:” 2nd blk 8page(b) Solve the questions:10 x 1 – x 2 + 2 x 3 = 4

 x 1 + 10 x 2 – x 3 = 32 x 1 + 3 x 2 + 20 x 3 = 7

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 9/13

using the LU decomposition method. Ans:

I got the values as

L11 = 10

L21 = 1

L22 = 101/10

L31 = 2

L32 = 32/10

L33 = 2018/101

U12 = -1/10

U13 = 1/5

U23 = -12/101

Using LUX = B

let UX = y

LY = B

10y1 = 4

y1 = 4/10

y1 + 101/10 y2 = 3

y2 = 26 /101

2y1 +32/10 y2 + 2018/101 y3 = 7

y3 = 543/2018

Now solving UX = Y

 The equation are..

x1 -1/10 x2 + 1/5 x3 = 4/10

x2 - 12/101 x3 = 26/101

x3 = 543/2018 = 0.269

x2 = 58984/203818 = .289

x1 = 76457/203818 = 0.375

 You can verify the answer by substituting it in the given equation.

Question 5: Out of the three method i.e. Secant method, Regula Falsimethod and the Newton Raphson method which method is moreefficient and why? Determine the efficiency or the order of these

three methods?Ans:

 The Newton-Raphson method is considered to be the fastest method. But the method

approaches to the root only when the initial guess is chosen very near the root. If the initial

guess is not near the actual root, the method may diverge. The Secant method gives better

results than Regula Falsi method method. But the Secant method may not converge to the

root sometimes. But the Regula Falsi method always converges.

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 10/13

If f '(x) evaluation is not difficult then Newton Raphson method is recommended. If 

evaluation of f '(x) is difficult then Secant method is recommended. But the convergence

must be verified using bisection method once in every 10 iterations.

 This is a detailed examination of four methods of discovering roots and the effects of different equations on the efficiency of each method and the amount of error produced by

each method. Although some calculation here has been done by hand, the vast majority of our conclusions were arrived at by using computer programs for each of the methods. Thefour methods examined were bisection, false-position, secant, and Newton. Each methodseemed to have a particular type of equation or desirable outcome for which it is mostefficient.

Secant

One of the faster methods, compared to bisection and false position, for approximating rootsis the secant method. Unlike the other two methods, f(a) and f(b) of the two initial valuesthat we pick to start with do not have be on opposites sides of the root and have a signchange. This one works by always making the old b value into the new a value. The new bvalue then becomes the zero of the secant line.

One of the problems with this method is that the slope of the secant line can become verysmall and this will cause it to move very far from the points you have. This method failswhen estimating the roots of an equation, which has a very low slope near the root becausethe secant line will jump large amounts due to the low slope. Another problem is that thismethod like the false position method does not know when to stop. It must be performedseveral times until the f of the current guess is very small.

Newton’s Method

Newton’s method is generally used in calculus to approximate roots. One main differencebetween Newton and other methods is that it only requires one initial guess instead of two.

Also, if the guess is relatively close to a root, Newton's method works incredibly fast. If theguess is not close to a root, however, Newton’s method can work slowly and, depending onthe function, may be impossible to use.

One similarity between Newton’s method and the bisection method is that both approximateroots in a consistent fashion. This allows the user to predict exactly how long it will take toarrive at a root, assuming the function and the original guess are sufficiently "nice" forNewton’s method. Newton’s method doubles in precision with each step. This is why Newtonrequires the same number of steps in Table B, regardless of the value of n in the equation.

Newton’s method uses not only the function itself but also the derivative of that function toapproximate the root. One chooses a point ‘a’. Throughout the course of the method, thiswill be replaced by the zero of the tangent line (the zero of the derivative). To find the new

point, use the formula [a – (f(a))/(f’(a))]. This will be the new ‘a’, and one repeats thisprocess until the root is found to sufficient precision.

Another interesting possibility with Newton’s method is error calculation.

Error calculations simply show the difference between the values arrived at by some methodand the actual value. Notice below where R is the root and x is the result of the most recentNewton iteration.

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 11/13

Error = x - R

New Error = x- (f(x)/f'(x))-R ~ f(x) and f'(x) are expanded out to a powerseries.

With the Newton's method, we make the assumption that X is close enough to R so that the

first nonzero term in the power series in numerator and denominator is almost the entireerror. Finally, following this assumption, one can determine that the new error is about (x-R)/2, which means that the error is cut in half each time.

False Position

Another method used for estimating roots of equations is the false position method. Thismethod functions by first starting with two endpoints a and b. If f(a) and f(b) are not roots,then f(a) times f(b) is a negative value since they both need to lie on opposites sides of theroot. This follows the logic that a negative value times a positive value equals a negativevalue. After the endpoints are chosen, false position finds the zero of the secant line joining(a,f(a)) and (b,f(b)) and then setting that as its new endpoint. This is done repetitively as theendpoints become continually closer to the root. An examination of the computer code for

the false position method shows that it is very similar to the bisection method except that ituses the zero of the secant line to approach the root rather then finding the midpoint eachtime.

 The false position method is often significantly faster then the bisection method forequations such as y = xn –2 for a small value of n. When n becomes large then false positionoften becomes the slowest method. In the data section of this paper, table B shows thenumber of repetitions for each method and value of n using the equation y = xn-2.

Data

 Table A:

f(x) = x2 – 2 a = 1 b = 2 accuracy within 0.00001

Method Name Number of steps

Bisection 17 steps

False – Position 8 steps

Secant 5 steps

Newton 4 steps

 Table B:

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 12/13

For f(x) = xn – 2, a = 1, b = 2, n = {3, 4,…, 10} and accuracy within 0.0001

Number of steps n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 N = 10

Bisection 17 17 17 17 17 17 17 17

False – Position 13 20 31 49 76 120 189 296

Secant 6 7 7 7 8 8 8 8

Newton’s 4 4 4 4 4 4 4 4

 Table C:

For f(x) = x2 – 2, a = 1, b = 2, done for 25 iterations of each method, the error was:

Method: Error:

Bisection 9.501 x 10-8

False-Position -2.420323 x 10-8

Secant -2.420323 x 10-8

Newton -2.420323 x 10-8

For secant and Newton, the program was not able to complete 25 iterations. After 6iterations, the memory overflowed.

Analysis of Data

 The above data produces "nice" endpoints since the functions that were examined are alsoideal. Even so, there was a lot of variation in the speed, accuracy, and reliability of eachmethod. Table A shows the variation in speed between all four methods. It is clear that inthis case Newton’s method would be a good choice for finding the root.

8/23/2019 MCSE-004 Solved Assignment 2012-13

http://slidepdf.com/reader/full/mcse-004-solved-assignment-2012-13 13/13

In Table B, one can see the consistency with which the bisection and Newton methods workfor nice functions. This same consistency could be seen using the bisection method on anyfunction, but Newton requires a relatively calm function in order to be helpful. One can alsosee that one method’s definition of a nice function is not the same as another method’sdefinition. Newton will work well on any non-oscillating, non-asymptotic function whoseslope is not very close to zero. Nearly any polynomial fits this description. However, the false

-position method’s effectiveness is inversely proportional to the degree of the polynomial.False-position’s definition of a nice function would be something more on the order of a low –degree function.

 Table C shows the degree of accuracy, which can be achieved in 25 iterations of eachmethod. The errors for all the methods are the same except for the bisection method. Thisonce again emphasizes how relatively fast the other three are for functions they considernice. The main problem encountered in this exercise had to do with the speed of thesefunctions. Because they worked so quickly, within six steps secant and Newton’s methodshad produced results, which were as accurate as the computer’s memory could hold. Aftersix iterations, the computer would have a memory overflow. We corrected this by alteringthe number of iterations.

Conclusion

It was shown first-hand in this analysis that the speed of the method was inverselyproportional to the consistency of the method to deal with non-nice functions. Newton’smethod originally seemed to be an exception to this rule, because it was about five times asfast as bisection, but just as consistent for xn – 2 for all n. It was after trying some functionsof different forms that one can find that the functions which are nice for Newton’s methodare different than those for false-position and secant methods. These non-nice functions areeasily found for Newton’s method, which makes Newton inconsistent and unable toefficiently solve for the root.

For nice functions and guesses relatively close to the root, each of the methods used requirerelatively few iterations before coming very close to that root. By examining the type of 

function, one can determine which sort of method would be most efficient in finding theroot.