Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help with the following program. its a tridiagonal algorithm that wh

ID: 3769687 • Letter: C

Question


Can someone help with the following program. its a tridiagonal algorithm that when I try to compile it either times out or gets killed. Is there another way to try to get this tridiagonal algorithm

? please help

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

double alpha;

int m;

int u;

int n;

double deltax;

double a  [10];

double b [10];

double c [10];

double d [10];

double T [10];

alpha=0.01;

m=100;

u=1;

n=10;

deltax= 1/m;

b[1]=-2*(2*alpha/u*deltax);

c[1]=(2*alpha-u*deltax)/(u*deltax);

a[3]= (2*alpha/u*deltax) + 1;

for (int i =2; i< n-2; i++)

{

d[i]=d[i]/b[i];

c[i]=c[i]/b[i];

b[i]=1;

d[i+1]=d[i+1]-a[i+1]*d[i];

b[i+1]=b[i+1]-a[i+1]*c[i];

}

T[n-1]=d[n-1]/b[n-1];

for (int i=n-2;2;-1)

{

T[i]=d[i]-c[i]*T[i+1];

}

cout << T;

return 0;

}

Explanation / Answer

Look at this part of code:

for (int i=n-2;i>=2;i--){
       T[i]=d[i]-c[i]*T[i+1];
   }

You have written it wrongly.

Your code:

for (int i=n-2;2;-1){
       T[i]=d[i]-c[i]*T[i+1];
   }

So change this part it will work now.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote