Name: Reem Mohamed Hamdi Khalil
Mechanical Power department, level 2.
Solution of Midterm Question:
1) The polynomial equation
X^4−(13+ε) x^3+(57+8ε)x^2−(95+17ε) x+50+10ε=0
has roots 1, 2, 5, 5+ε. Use the functions Bairstow and roots to find all the roots of this
polynomial for ε = 0.1, 0.01,0.001. What happens as ε becomes smaller? Use an
accuracy of 10^−5.
Algorithm:
1. Define f(x) and f'(x) .2. Set desired or given tolerance (es) and initial guesses (xi).
3. For each initial guess xi: a. Set ea. = large number (initial error). b. While ea. > es i. Compute Xin = xi - f(xi) / f'(xi) ii. Calculate ea. = abs((Xin - xi) / Xin) iii. Update xi = Xin Store the root found in
roots array 4. Output all found roots
1
2- For the data given by the vectors
x= 0 : 0.25: 3
and
y=[6.3806 7.1338 9.1662 11.5545 15.6414 22.7371 32.0696 47.0756 73.1596 111.4684 175.989
5 278.5550 446.4441]
fit the following function:
f(x)=a+ce^2x
using the MATLAB function.
Algorithm:
Summarized Algorithm for Polynomial Curve Fitting:
2
1.
Input Data: Define the x data points and corresponding y data points (logarithmic values). ,Set the degree D of the polynomial.
2.
Create Matrix A =2In(a): Construct matrix A where each element A(i,j) is the sum of x raised to the power (i + j - 2).
3.
Create Vector B=In(a)*In(c): Create a vector B where each element B(i) is the sum of x^(i-1) * y.
4.
Solve System of Equations:Solve the system A * U = B using matrix division to get the polynomial coefficients U.
5.
Display Polynomial: Print the polynomial equation using the coefficients in U.
6.
Plot Results: Use polyval to evaluate the polynomial over a range of x values, Plot the fitted polynomial curve (yc) and the original data points (x, y) with maroon circles.
3- Determine the roots of the equation
Asin (3θ)+Bcos(2θ) +Csin(θ)+1=0
where A=0.157, B=−0.940, and C=−0.900.
Hint: Expand sin (3θ) and cos2(θ) in terms of powers of sin(θ) and solve the
resultant polynomial using the MATLAB function roots to obtain values for
sin(θ) and hence θ.
Algorithm:
Summarized Algorithm for Newton-Raphson Method:
1.
Define the function f(θ)f(\theta) and its derivative f′(θ)f'(\theta) based on the given equation.
2.
Initialize:
o Set initial guess θ0\theta.
o Define the allowable error( es=10^-5).
o Set initial error to a large value (ea=1).
3.
Repeat until convergence:
o Compute θnew=θ−f(θ)f′(θ)\theta_{\text{new}} = \theta - \frac{f(\theta)}{f'(\theta)}.
o Calculate the error: ea
o Update θ=θnew
3
4.
Stop when ea<es
5.
Output the root θ and sin(θ)
4. Since all but one parameter is optional, there are many forms
of this function. We cannot give examples of all these forms but the cases illustrate
its use.
Following:
>>colpos=[1 2 1 2 5 3 4 3 4 5];
>>rowpos=[1 1 2 2 2 4 4 5 5 5];
>>value=[12 -4 7 3 -8 -13 11 2 7 -4];
>> A = sparse(rowpos, colpos, value,5,5)
Find the value of x1 to x5 using Gauss Seidel methods
Algorithm:
Summarized Algorithm: Gauss-Seidel with Diagonal Dominance
1.
Input: Matrix A, vector b, tolerance es, and maximum iterations.
2.
Ensure Diagonal Dominance: Modify matrix AA so each diagonal element is larger than the sum of the off-diagonal elements in the row.
3.
Initialization: Start with initial guess x=0.
4.
Gauss-Seidel Iteration: For each row, update each xi=Xin
5.
4
o
Check convergence: stop if the solution change is smaller than eses.
o
Display the solution or a warning if convergence isn't achieved.
Output: