Commit c8fd0bf4 authored by s-jdoyle4's avatar s-jdoyle4
Browse files

Home work two implimenting orthog from book with writing a modified gram-schmidt prob 2.14.

parent bf6af59b
//This program copy from pg 17 to 19 in the book
#include <iostream>
using namespace std;
int main() {
double a[3+1], b[3+1];
cout << "Enter the first vector" << endl;
int i;
for( i=1; i<=3; i++) {
cout << " a[" << i << "] = ";
cin >> a[i];}
cout << "Enter the second vector" << endl;
for( i=1; i<=3; i++ ) {
cout << " b[" << i << "] = ";
cin >> b[i];
}
double a_dot_b = 0.0;
for( i=1; i<=3; i++ )
a_dot_b += a[i]*b[i];
if( a_dot_b == 0.0)
cout << "Vectors are orthogonal" << endl;
else {
cout << "Vectors are NOT orthogonal" << endl;
cout << "Dot product = " << a_dot_b << endl;
}
return 0;}
File added
//This program copy from pg 17 to 19 in the book
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a[3+1], b[3+1];
cout << "Enter the first vector" << endl;
int i;
for( i=1; i<=3; i++) {
cout << " a[" << i << "] = ";
cin >> a[i];}
cout << "Enter the second vector" << endl;
for( i=1; i<=3; i++ ) {
cout << " b[" << i << "] = ";
cin >> b[i];
}
double a_dot_b = 0.0;
for( i=1; i<=3; i++ )
a_dot_b += a[i]*b[i];
if( a_dot_b == 0.0)
cout << "Vectors are orthogonal" << endl;
else {
cout << "Vectors are NOT orthogonal" << endl;
cout << "Dot product = " << a_dot_b << endl;
double v2[3+1], a_dot_a = 0.0, v3[3+1], v4, v5, v6[3+1];
for( i=1; i<=3; i++ ) {
a_dot_a += a[i]*a[i];
v2[i] += a_dot_b*a[i];
v3[i] += b[i] - v2[i]/a_dot_a;
v4 = sqrt (v3[i]*v3[i]);
v5 = sqrt (b[i]*b[i]);
v6[i] = v3[i]*v5/v4;
cout << v6[i] << endl;
}}
return 0; }
File added
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment