Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WHAT AM I DOING WRONG??? #include #include typedef struct{ double x, y, z; }vector; vector initVect(double x, double y, double z); vector invVect(vector v); double

image text in transcribedimage text in transcribed

WHAT AM I DOING WRONG???

#include #include

typedef struct{ double x, y, z; }vector;

vector initVect(double x, double y, double z); vector invVect(vector v); double normVect(vector v); vector addVect(vector v1, vector v2); double distVect(vector v1, vector v2); double prodVect(vector v1, vector v2); double projVect(vector v1, vector v2); double angleVect(vector v1, vector v2); void printVect(char *msg, vector v);

int main() {

vector v1, v2, sum, diff; double x, y, z;

//printf("Enter the x, y and z for vector 1: "); scanf("%lf %lf %lf", &x, &y, &z); v1 = initVect(x, y, z);

//printf("Enter the x, y and z for vector 2: "); scanf("%lf %lf %lf", &x, &y, &z); v2 = initVect(x, y, z);

sum = addVect(v1, v2); diff = addVect(v2, invVect(v1));

printVect("v1:", v1); printVect("v2:", v2); printVect("v2 + v1:", sum); printVect("v2 - v1:", diff); printf("norm(v1): %.2f ", normVect(v1)); printf("norm(v2): %.2f ", normVect(v2)); printf("dist(v1,v2): %.2f ", distVect(v1, v2)); printf("prod(v1,v2): %.2f ", prodVect(v1, v2)); printf("proj(v1,v2): %.2f ", projVect(v1, v2)); printf("proj(v2,v1): %.2f ", projVect(v2, v1)); printf("angle(v2,v1): %.2f ", angleVect(v2, v1));

return 0; } vector initVect(double x, double y, double z) { vector v; v.x = x; v.y = y; v.z = z; return v; } vector invVect(vector v) { vector inv; inv.x = -v.x; inv.y = -v.y; inv.z = -v.z; return inv;

} double normVect(vector v) { double s = v.x * v.x; s += v.y * v.y; s += v.z * v.z; return sqrt(s); } vector addVect(vector v1, vector v2) { vector v3; v3.x = v1.x + v2.x; v3.y = v1.y + v2.y; v3.z = v1.z + v2.z; return v3; } double distVect(vector v1, vector v2) { double dx = v2.x - v1.x; double dy = v2.y - v1.y; double dz = v2.z - v1.z; double s = dx * dx + dy * dy + dz * dz; return sqrt(s); } double prodVect(vector v1, vector v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } double projVect(vector v1, vector v2) { double n = normVect(v2); if(n == 0) return 0; else return prodVect(v1, v2) / n; } double angleVect(vector v1, vector v2) { double n1 = normVect(v1); double n2 = normVect(v2); double s = prodVect(v1, v2); double pi = 3.14159265;

if(n1 == 0 || n2 == 0) return 0; else { return acos(s/(n1*n2)) * 180 / pi; } }

void printVect(char *msg, vector v) { printf("%s (%.2f, %.2f, %.2f) ", msg, v.x, v.y, v.z); }

13.24 Structs-Ex Requirements (Read Carefully) Define a structure data type that holds three double data members (xyz). . Define an alias for this data type named vector (using typedef). Create a function named initVect that receives three double numbers and returns vector structure initialized with the values passed to the function where the first parameter is the value for data member x and the last one for data member z. Create a function named invVect that takes a vector structure and returns the inverse of the vector (negative value of each data member xyz). Create a function named normVect that takes a vector structure and returns the Euclidean norm of the vector defined as: . .Create a function named addVect that takes two vector structures and returns a vector structure with the sum of both vectors passed to the function. Create a function named distVect that takes two vector structures and returns the Euclidean distance between the two vectors defined as: e distance 2-x102-yl?(22 -zl? Create a function named prodVect that takes two vector structures and returns the scalar product of both vectors defined as: .Create a function named projVect that takes two vector structures and returns the scalar projection of the first vector onto the second vector defined below. If the norm of v2 is zero then return 0. v1 v2 Iv2 proj- v1. v2 proj- . Create a function named angleVect that takes two vector structures and returns the angle in degrees between the two vectors defined below. For computing the cosine inverse use the function acos. Use Pl = 3.14159265. If the norm of any of the two vectors is zero then return 0. mple _ cos"(?:/??).? nglecos Tasks (Read Carefully) Create a program that reads two vectors from the user as follows: (10.4, 7.4, 3.0) (1.4, 2.4, 1.3) Then have your program output the following (add n' after every line): vl: (10.40, 7.40, 3.00) v2: (1.40, 2.40, 1.30) v2 v1: (11.80, 9.80, 4.30) v2_v1: (-9.00, -5.00, -1.70) norm (vl: 13.11 norm (v2) 3.07 dist (vl,v2): 10.44 prod (vl, v2): 36.22 proj (vl,v2): 11.81 proj (v2,vl): 2.76 angle (v2,vl) 25.77

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions