Page 1 of 1

D00 von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include #include #include #i

Posted: Fri May 20, 2022 11:24 am
by answerhappygod
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 1
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 1 (57.21 KiB) Viewed 32 times
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 2
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 2 (49.88 KiB) Viewed 32 times
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 3
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 3 (31.06 KiB) Viewed 32 times
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 4
D00 Von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Include Stdio H Include Stdlib H Include String H I 4 (48.75 KiB) Viewed 32 times
D00 von 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> typedef struct{ double x; double y; double z; } Vector; void print_vector(const Vector v); Vector sum (const Vector vi, const Vector v2); Vector diff(const Vector vi, const Vector v2); double dot_product(const Vector vi, const Vector v2); Vector cross_product(const Vector vi, const Vector v2); double norm(const Vector v); int is_unitvector(const Vector v); Vector unit(const Vector v); Vector multiplyby_scalar (const Vector vi, const double c); double angle(const Vector vi, const Vector v2); double distance(const Vector vi, const Vector v2); int are_linearly_independent (const Vector vi, const Vector v2, const Vector v3); int are orthogonal(const Vector vi, const Vector v2, const Vector v3); int are orthonormal(const Vector vi, const Vector v2, const Vector v3); Vector projection(const Vector vi, const Vector v2); Vector orthogonal projection(const Vector vi, const Vector v2); int convert_2_orthogonal_basis(Vector "v1, Vector *v2, Vector *v3); char* vector2str (const Vector v); 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 int main() { Vector vi = {1, 2, 2}, v2 = {-1, e, 2}, v3 = {@, e, 1); double k = 2; printf("v1 = "); print_vector(v1); printf("v2 = "); print_vector(v2); printf("v3 - "); print_vector(v3);

= F叶归加印昭阳红弘8码8%切898a&Egg阳5%的阳江2四四四形刀沿四%888时时 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 printf("v1 + V2 = *); print_vector(sum(v1, v2)); printf("v1 - v2 - "); print_vector (diff(vi, v2)); printf("k* vi = "); print_vector (multiplyby_scalar (vi, k)); printf("vi. V2 = %.21f\n", dot_product(v1, v2)); printf("v1 x V2 = "); print_vector (cross_product(v1, v2)); printf("| vi| %.21f\n", nor (v1)); if(is_unitvector (v1)) printf("vi is a unit vector. In"); else printf("\1 is not unit vector. \n"); printf("unit( vi ) = "); print_vector (unit(v1)); printf("angle(v1, v2) = %.21f\n", angle(v1, v2)); printf("distance(v1, v2) = %.21f\n", distance(v1, v2)); if (are_linearly_independent (v1, v2, v3)) printf("Vectors are linearly independent. \n"); else printf("Vectors are not linearly independent. \n"); 76 77 78 79 80 81 82 83 84 85 if(are_orthogonal(v1, v2, v3)) printf("Vectors are orthogonal.\n"); else printf("Vectors are not orthogonal. \n"); if(are_orthonormal(v1, V2, V3)) printf("Vectors are orthonormal. \n"); else printf("Vectors are not orthonormal.\n");

86 87 88 89 printf("Projection of vi onto v2 is = "); print_vector (projection (v1, v2)); printf("Orthogonal projection of v1 onto v2 is = "); print_vector (orthogonal_projection (v1, v2)); 92 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 if (convert_2_orthogonal_basis(&vi, &v2, 8v3)){ printf("Orthogonalization of vectors:\n"); printf("v1 = "); print_vector (v1); printf("v2 = "); print_vector(v2); printf("v3 = "); print_vector(v3); } puts (vector2str(v1)); return 0; }

Complete the C program that makes many operations on 3D vector spaces by considering the following details. The program contains a structure which represents a 3D vector, the main function and many functions prototypes. You must write the functions whose prototypes have been given. You can change the main function to check the possible results. Do not change the other codes (the structure and function prototypes). A sample output is given below for the given main function: vi - (1.00, 2.00, 2.00) V2 = (-1.ee, e.ee, 2.00) V3 - (e.ee, e.ee, 1.ee) vi + V2 - (e.ee, 2.00, 4.00) v1 = v2 = (2.ee, 2.ee, 8.00) KV1 - (2.ee, 4.ee, 4.00) v1 . V2 - 3.00 vi x v2 - (4.00, -4.ee, 2.00) | v1 | - 3.ee vi is not unit vector. unit( vi ) = (0.33, 0.67, 0.67) angle(v1, v2) - 1.11 distance(v1, v2) = 2.83 Vectors are linearly independent. Vectors are not orthogonal. Vectors are not orthonormal. Projection of vi onto v2 is - (-0.6e, e.ee, 1.20) Orthogonal projection of v1 onto v2 is - (1.60, 2.ee, 2.80) Orthogonalization of vectors: vi - (1.ee, 2.ee, 2.00) V2 = (-1.33, -0.67, 1.33) V3 = (0.22, -2.22, 0.11) (1.00, 2.00, 2.00) Process exited after e.e1459 seconds with return value o Press any key to continue