Homework 2 Spring 2025
Homework 2 Spring 2025
Problem 1: (30pts)
a. Write a function that computes the roots of a quadratic equation, q(x) = ax2 + bx + c.
(10pts)
b. To your function codes, add another main file (2pts) where the user is prompted to
enter the value for a, b and c. Enter the values (a, b, c) = (1, 2, −3) and provide the
c. Enter the one after the other the values (a, b, c) = (1, 1.2123, 2), (1, 12.123, 2), (1, 121.23, 2),
(1, 1212.3, 2) and provide the roots corresponding to these cases. (4pts)
d. Similarly, write another main file, where a, b, c are chosen randomly and print the ran-
domly generated set of numbers a, b, c on the screen. Provide the roots corresponding to
three random choices of the coefficients a, b, c and for each choice of the triplet (a, b, c)
provide in addition the graph of the quadratic function. (7pts) Run your codes three
e. Find the zeros of the fourth degree polynomial equation 9x4 − 61x2 + 100 = 0. Explain
how you will proceed to solve this equation using the Matlab code in (a.) (3pts)
1
Problem 2: (10pts)
In the absence of air resistance, the cartesian coordinates of a projectile launched with
x = v0 cos(θ0 ) t ,
y = v0 sin(θ0 ) t − 0.5gt2 ,
b. Based on the trajectory, find approximately the coordinates of the highest point the
projectile will reach and the point he will hit the ground. (2pts)
Problem 3: (20pts)
∑
∞
2n + 1
n=0
2n
∑
∞
3n + 1
√
n=0
n5 + 4n2 + 12
2
d. Write a Matlab script file to calculate the following limit (4pts)
∑
∞
ln(n2 )
n=2
n2
sin(x11 )
lim
x −→ 0 x7
−x3 + + x3 cos(x2 )
2
Problem 4: (10pts)
( )
ln (ax8 + bx4 + cx3 + dx2 + e)5
Draw the plot of the function, f (x) = on the inter-
(f x2 + g)
vals, [−5, 5] and [−10, 10] for a = 5, b = −6, c = 4, d = 21, e = 14, f = 1, g = 3. Make
sure your provide a label for the x-axis and the y-axis as well as a title that says plot
( )
ln (ax8 + bx4 + cx3 + dx2 + e)5
of the given function, f (x) = , for a = 5, b = −6, c =
(f x2 + g)
4, d = 21, e = 14, f = 1, g = 3. Add a grid to your plot.
Problem 5: (30pts)
a. Using MATLAB, confirm that the LU factorization ([L, U ] = lu(D)) out-performs the
the following system of linear equations written in matrix form Dy = b, where the
D = [4 2 3; 5 − 8 1; 4 7 − 9]
b = [1 4 0]′ .
3
b. Redo the same task above by generating a set of m random integer values for the vector
b between 1 and 100 inclusive and compare the speed of each methodology for a bunch
of different number of iterations (m = 1000, 50, 000, and 100, 000 simulations). Here,
you must use a for loop. Provide the clock time to execute the m calculations in each
c. The matrix A and the column vectors b and y are defined as follows:
0.780 0.563 0.217 −1
A= , b= , y= .
0.913 0.659 0.254 1
e. Using Matlab, solve the linear equations Ax = b. Use both the LU decomposition and
Using Matlab solve the perturbed system of equation (A + E)yE = b. Use both the LU
decomposition and the Gaussian elimination method. (5pts) Discuss your funding.
(1pt)