You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

trial.c 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <stdio.h>
  2. #include <cblas.h>
  3. int main() {
  4. int n = 4;
  5. double x[] = {1, 2, 3, 4};
  6. double y[] = {5, 6, 7, 8};
  7. double c = 0.5; // cosine of the angle
  8. double s = 0.5; // sine of the angle
  9. double a = 2.0; // scalar for axpy and scal
  10. // Apply the rotation
  11. cblas_drot(n, x, 1, y, 1, c, s);
  12. // Perform AXPY operation: y = a*x + y
  13. cblas_daxpy(n, a, x, 1, y, 1);
  14. // Swap vectors x and y
  15. cblas_dswap(n, x, 1, y, 1);
  16. // Copy vector x to y
  17. cblas_dcopy(n, x, 1, y, 1);
  18. // Scale vector x by a
  19. cblas_dscal(n, a, x, 1);
  20. // Compute dot product of x and y
  21. double dot_product = cblas_ddot(n, x, 1, y, 1);
  22. // Compute sum of absolute values of elements in x
  23. double asum = cblas_dasum(n, x, 1);
  24. // Compute Euclidean norm (L2 norm) of vector x
  25. double norm = cblas_dnrm2(n, x, 1);
  26. // Find index of maximum absolute value in x
  27. int index_max = cblas_idamax(n, x, 1);
  28. // Find index of minimum absolute value in x
  29. int index_min = cblas_idamin(n, x, 1);
  30. // Print the results
  31. printf("Resulting vectors:\n");
  32. printf("x: ");
  33. for (int i = 0; i < n; i++) {
  34. printf("%f ", x[i]);
  35. }
  36. printf("\n");
  37. printf("y: ");
  38. for (int i = 0; i < n; i++) {
  39. printf("%f ", y[i]);
  40. }
  41. printf("\n");
  42. printf("Dot product: %f\n", dot_product);
  43. printf("Asum: %f\n", asum);
  44. printf("Norm: %f\n", norm);
  45. printf("Index of max absolute value in x: %d\n", index_max);
  46. printf("Index of min absolute value in x: %d\n", index_min);
  47. return 0;
  48. }