I cannot use double subscripts, 2d arrays, or nested for loops for this problem.
ID: 3829614 • Letter: I
Question
I cannot use double subscripts, 2d arrays, or nested for loops for this problem. Here is the algorithm I have come up with so far:
L0[1] = sqrt(a[1]);
L1[1] = 1 / L0[1];
L2[1] = b[1] / L0[1];
L0[2] = sqrt(a[2] - (L1[1] / L0[1]) * (L1[1] / L0[1]));
L1[2] = (0 - (L2[1]) * (L1[1])) / L0[2];
L0[3] = sqrt(a[3] - (L2[1]) * (L2[1]) - (L1[2]) * (L1[2]));
for(i = 3; i <= n; i++)
{
L2[i-2] = (b[i-2] - b[i-3] * b[i-4]) / b[i-2];
L1[i-1] = (L0[i] - (L2[i]) * (L1[i])) / L0[i];
L0[i] = sqrt(L0[i] - (L1[i]) * (L1[i]) - (L2[i]) * (L2[i]));
}
I'm not sure what to add or change in this solution.
1) Let A be a symmetric pentadiagonal positive definite matrix of the form Cal 1 0 0 0 a, 0 bo 0 a 0 ba 0 0 2 0 b 0 bn 0 an n-4 m-2 0 b am-1 an n-2 Write an algorithm that generates a lower-triangular L such that A -LL'. That is, construct the vectors LO, LI, L2 so that LO L1 LO 0 L2 L1 LO 0 0 L2 LO L1 n-2 Use the given single subscripting and fully exploit the sparsity pattern. Assume that n 23. Hint: The number of special cases can be reduced by working one row at a time.Explanation / Answer
An element in 2-dimensional array is accessed by using the subscripts, i.e., row index and column index of the array. For example:
The above statement will take 4th element from the 3rd row of the array. You can verify it in the above diagram. Let us check below program where we have used nested loop to handle a two dimensional array:
When the above code is compiled and executed, it produces the following result:
As explained above, you can have arrays with any number of dimensions, although it is likely that most of the arrays you create will be of one or two dimensions.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.