t[row][col] = update;
}
}
done = (maxDiff < tolerance);
}
/* Print results. */
cout << “Equilibrium values:” << endl;
for (row=0; row<NROWS; row++)
{
return 0;
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Problem chapter8_22 */
/* */
/* This program models a temperature distribution for a grid */
/* with six rows and eight columns. The user enters the */
#include <iostream>
#include <cstdlib>
#include <cmath>
int main()
{
/* Declare and initialize variables. */
int row, col;
bool done(false);
/* This function receives a double array a of size N by N+1, where */
/* N is a symbolic constant. A second parameter is a double */
/* array soln of size N. The function solves the system of */
/* equations represented by array a, and returns the solution in */
/* the array soln. */
void gauss(double a[][N+1], double soln[])
{
/* Declare variables. */
int i, j, k;
double sum, mult;
}
}
/* Now do the backwards substitution. */
for (i=N-1; i>=0; i–){
sum = a[i][N];
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Problem chapter8_24 */
/* */
/* This funtion receives a double array a of size N by N+1, where */
/* N is a symbolic constant. A second parameter is a double */
/* array soln of size N. The function solves the system of */
/* Can’t divide by zero. */
if (a[i][i] == 0){
cout << “Can not solve this equation.” << endl;
}
}
}
/* Now do the backwards substitution. */
for (i=N-1; i>=0; i–)
{
}
/*——————————————————————–/*
/*——————————————————————–*/
/* Problem chapter8_25 */
/* */
/* This function receives a two-dimensional array and a pivot */
/* value that specifies the coefficient of interest, j. The */
/* Assume that the jth row is already the correct one. */
max_j = a[j][j];
row = j;
if (fabs(a[i][j]) > max_j){
max_j = a[i][j];
row = i;
}
}
/* Return to calling function. */
return;
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Problem chapter8_26 */
/* */
/* This funtion receives a double array a of size N by N+1, where */
/* N is a symbolic constant. A second parameter is a double */
/*——————————————————————–*/
/* Problem chapter8_26 */
/* */
/* This function that receives a two-dimensional array and a pivot */
/* value that specifies the coefficient of interest, j. The */
/* function reorders all columns starting with the jth column */
/* such that the jth column will have the largest coefficient */
/* For each column, starting with the jth. */
for (i=j; i<N; i++)
/* Find the maximum value of the columns in these equations */
if (fabs(a[j][i]) > max_j){
max_j = a[j][i];
}
}
/* Keep track of the switch in k. */
tmp = k[j];
k[j] = k[col];
k[col] = tmp;
/* Return to calling function. */
return;
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Set up k before pivoting. */
for (i=0; i<N; i++)
k[i] = i;
/* First do the elimination. */
for (i=0; i<N-1; i++){
/* Column pivot */
pivot_c(a,i,k);
}
/* Now do the backwards substitution. */
for (i=N-1; i>=0; i–){
sum = a[i][N];
for (m=1; m<N-i; m++)
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Problem chapter8_28 */
/* */
/* This funtion receives a double array a of size N by N+1, where */
/* N is a symbolic constant. A second parameter is a double */
/* array soln of size N. The function solves the system of */
/* First do the elimination. */
for (i=0; i<N-1; i++)
{
/* Row pivot. */
pivot_r(a,i);
for (m=1; m<N-i; m++)
sum += –a[i][N-m] * tmp[N-m];
tmp[i] = sum / a[i][N-m];
}
}
/*——————————————————————–*/
Determinates
/*——————————————————————–*/
/* Problem chapter8_29 */
/* */
/* This function computes the minor of a square matrix */
/* with four rows and four columns. */
double minor(double a[][4], int row, int col)
{
/* Declare and initialize variables. */
int i, j, r=0, c=0;
double m[3][3], det;
}
}
/* Now calculated determinant m. */
det = m[0][0]*m[1][1]*m[2][2] +
m[0][1]*m[1][2]*m[2][0] +
/* */
/* This function computes the cofactor of a square matrix */
/* with four rows and four columns, where the (i,j) cofactor */
/* is (-1)^(i+j) * minor(a,i,j) */
/* Declare function prototypes. */
double minor(double a[][4], int i, int j);
/* Declare function prototypes */
double cofactor(double a[][4], int i, int j);
double det_c(double a[][4])
{
/* Declare variables */
int i, column=0;
double sum=0;
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Program chapter8_33 */
/* */
/* This function computes the determinant of a square matrix */
/* with four rows and four columns by multiplying each element */
/* in a given row by its cofactor and adding the products. */
/* Declare function prototypes */
double cofactor(double a[][4], int i, int j);
}
/*——————————————————————–*/
/*—————————————————-*/
/* Program chapter8_34.cpp */
/* This function generates a matrix transpose. */
#include<vector>
using namespace std;
}
}
// Void return.
return;
}
/*—————————————————-*/
/*—————————————————-*/
/* Program chapter8_35.cpp */
/* This function performs a matrix multiplication */
/* of two vectors using sums of products. */
#include<vector>
using namespace std;
}
}