Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

pro 1 . When n varies from 3 to 5 0 , TDMA methods are used to determine the displacement of x 1 in equilibrium

pro1. When n varies from 3 to 50, TDMA methods are used to determine the displacement of x1 in equilibrium to find n versus x1 and graph it. Using process C++
--------------------------------------------
I got the c++ code for question 1. However, I ran the c++ code, but an error occurred. I wonder what the problem is.(Please refer to the picture below)
Link to the answer I received : https://www.chegg.com/homework-help/questions-and-answers/pro1-n-varies-3-50-tdma-methods-used-determine-displacement-x1-equilibrium-find-n-versus-x-q180757385
The c++ code I received:
#include
#include
#include
// Function to perform TDMA (Thomas Algorithm)
void TDMA(const std::vector& a, const std::vector& b, const std::vector& c, std::vector& d, std::vector& x){
int n = b.size();
std::vector c_star(n,0.0);
std::vector d_star(n,0.0);
// Modify the coefficients
c_star[0]= c[0]/ b[0];
d_star[0]= d[0]/ b[0];
for (int i =1; i n; i++){
double m =1.0/(b[i]- a[i]* c_star[i -1]);
c_star[i]= c[i]* m;
d_star[i]=(d[i]- a[i]* d_star[i -1])* m;
}
// Back substitution
x[n -1]= d_star[n -1];
for (int i = n -2; i >=0; i--){
x[i]= d_star[i]- c_star[i]* x[i +1];
}
}
int main(){
// Open a file to write results
std::ofstream outfile("results.txt");
// Loop over different sizes of the matrix
for (int n =3; n =50; ++n){
// Initialize vectors for the tridiagonal matrix
std::vector a(n -1,-1.0); // Subdiagonal (a_1 to a_{n-1})
std::vector b(n,2.0); // Main diagonal (b_0 to b_{n-1})
std::vector c(n -1,-1.0); // Superdiagonal (c_0 to c_{n-2})
std::vector d(n,1.0); // Right-hand side (d_0 to d_{n-1})
// Vector to store the solution
std::vector x(n,0.0);
// Apply TDMA to solve the system
TDMA(a, b, c, d, x);
// Output the displacement x1
std::cout "n =" n ", x1=" x[0] std::endl;
outfile n "" x[0] std::endl;
}
// Close the file
outfile.close();
return 0;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

What are the purposes of strategic planning?

Answered: 1 week ago

Question

6. What qualifications are needed to perform the job?

Answered: 1 week ago