Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 4 : Complete the dot_product, cross_product and norm functions in the program below. Do not modify the main() function . Notice that since cross_product

Exercise 4: Complete the dot_product, cross_product and norm functions in the program below. Do not modify the main() function. Notice that since cross_product produces a vector, it must use pointers instead of a return value.

#include  #include  //dot_product(x1, y1, z1, x2, y2, z2) //Compute and return the dot product of the vectors (x1, y1, z1) and (x2, y2, z2) float dot_product( float x1, float y1, float z1, float x2, float y2, float z2 ){ //Your code here } //cross_product(x1, y1, z1, x2, y2, z2, result_x, result_y, result_z) //Compute the cross product of the vectors (x1, y1, z1) and (x2, y2, z2) //and store the result using the pointers result_x, result_y and result_z void cross_product( float x1, float y1, float z1, float x2, float y2, float z2, float* result_x, float* result_y, float* result_z){ //Your code here } //norm(x, y, z) //Compute and return the norm of the vector (x,y,z) //You may want to use the sqrt() function from math.h (notice that it is included above). float norm( float x, float y, float z ){ //Your code here } int main(){ float x1, y1, z1; float x2, y2, z2; float x3, y3, z3; x1 = 1; y1 = 2; z1 = 3; x2 = 4; y2 = 5; z2 = 6; float d = dot_product(x1,y1,z1, x2,y2,z2); cross_product(x1,y1,z1, x2,y2,z2, &x3,&y3,&z3); float n1 = norm(x1,y1,z1); float n2 = norm(x2,y2,z2); printf("v1 = (%f %f %f) ", x1, y1, z1); printf("v2 = (%f %f %f) ", x2, y2, z2); printf("v1 (dot) v2 = %f ", d); printf("v3 = v1 x v2 = (%f %f %f) ", x3, y3, z3); printf("norm(v1) = %f" , n1); printf("norm(v2) = %f" , n1); //Since (x3, y3, z3) is the cross product of v1 and v2, it should be //orthogonal to both v1 and v2 (so the dot product should be zero). float d13 = dot_product(x1,y1,z1, x3,y3,z3); float d23 = dot_product(x2,y2,z2, x3,y3,z3); printf("v1 (dot) v3 = %f ", d13); printf("v2 (dot) v3 = %f ", d23); return 0; } 

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

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions

Question

Ability to work comfortably in a team environment

Answered: 1 week ago

Question

Describe your ideal working day.

Answered: 1 week ago