Here is the problem I need help with: I need to write the answer in code form, b
ID: 3824514 • Letter: H
Question
Here is the problem I need help with:
I need to write the answer in code form, but not in full code. Somewhere about 3 to 9 lines of code. This is just a specialization of the general algorithm to solve a system via Gaussian Elimination. So I need to do the 2 phases: 1) eliminate values below the main diagonal, 2) back substitution on the upper triangular result.
So the elimination phase should involve a single loop whose body eliminates a[i] and b[i]. Each involves its own multiplier. Afterwards there will be another simple loop to handle the back solve.
The answer I was able to come up with is this:
for (i = 1; i < n; i++)
a[i+1] = a[i+1] – (b[i]/a[i])*c[i+1];
//endfor
x[n] = b[n] / a[n];
x[n-1] = (b[n-1] – c[n]*x[n]) / a[n-1];
for (i = n-2; i > 0; i--)
x[i] = (b[i] – c[i+1]*x[i+1] – d[i+2]*x[i+2]) / a[i];
//endfor
I'm not sure if this is the correct answer for this problem. If it isn't, which portions of the code do I need to change?
Write an et algorithm to soluko icient an n x n system On23 with nonzero dia aonals the form I n-3 A-2 n 2. te that A is non singular and that pinating YOU should first convert fo an Upper trt angularExplanation / Answer
this will get complited and confusing if you take matrix A as 4 array a[],b[],c[],and d[]. Keep it simple here is sample code
loop for the generation of upper triangular matrix
for(j=1; j<=n; j++)
{
for(i=j+1; i<=n; i++)
{
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
x[n]=A[n][n+1]/A[n][n];
//this loop is for backward substitution
for(i=n-1; i>=1; i--)
{
sum=0;
for(j=i+1; j<=n; j++)
{
sum=sum+A[i][j]*x[j];
}
x[i]=(A[i][n+1]-sum)/A[i][i];
}
this is simplest way to put this solution.