i need help in coding

profilewaheed03
assignment_2_coding.docx

Assignment 2 - Coding Problems: Due Friday 2/10/16

1. Matlab. Complete the quadratic equation solver yournameQuadEqn.m. See the comments at the top for specific directions, but the main idea is to avoid loss of significance by re-writing one of roots

.

· The formula for the root r1 has potential loss of significance when b > 0 and b2 > 4ac; The second root r2 is best left as is.

· The formula for the root r2 has potential loss of significance when b < 0 and b2 > 4ac. The first r1 is best left as is.

2. Write a C program for estimating adding numbers in a 2D grid. See the file yournameGridSum.c to get started. This program will exhibit the effect of cumulative rounding error (caused by adding a lot small values.) Consider an N × N grid (we’ll use N = 5000) dividing up the unit square into smaller squares. Therefore each subsquare has width w = 1/N. Let (xi,yj) denote the midpoint of the square in column i, row j. Note that

xi = (i − 0.5) ∗ w

Your job is to compute the double sum

N N

S = 3w2XX(xi)2 + (yj)2

j=1 i=1

For N large, the value of S should approach 2. You will compute S in two different ways: I. Summing up the numbers 1 by 1 in a nested for loop.

PSEUDOCODE

Initialize: width=1/N; sum1=0;

for loop: row=1 to N for loop: col=1 to N x = (col -0.5)*width y = (row - 0.5)*width sum1 = sum1 + (x*x + y*y)

end of inner loop

end of outer loop finalResult1= 3*width*width*sum1

II. Sum all the number in a row, then add to overall sum.

PSEUDOCODE

Initialize: sum2=0;

for loop: row=1 to N

rowSum=0; y= (row - 0.5)*width for loop: col=1 to N x = (col -0.5)*width rowSum = rowSum + (x*x + y*y)

end of inner loop sum2=sum2+ rowSum

end of outer loop finalResult2= 3*width*width*sum2