473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help with matrices

Can anyone tell me why the mult_matrix isnt working correctly? ignore extra text, this is a small section of a larger assignment... I'm stuck and any help would be appreciated thanks

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #define ROWA 4
  5. #define COLA 4
  6.  
  7. void prob1(void);
  8. void prob2(void);
  9. double unit_norm(double vec[4], int cols);
  10. void matrix_mult(double a[4][4],double b[4], double c[4], int rows);
  11. double unit_vec(double vec[4], int cols);
  12. double pmatrix(double **A, double **B, double *a, double *b, int n);
  13.  
  14.  
  15.  
  16.  
  17. double a[4][4], b[4], c[4];
  18. int n=4,t,  row, rows, col, cols, k;
  19.  
  20. main()
  21. {
  22.         int menu;
  23.         printf("Enter the function number to execute (1-2):");
  24.         scanf("%d", &menu);
  25.         switch(menu){
  26.          case 1:
  27.             prob1();
  28.             break;
  29.          case 2:
  30.             prob2();
  31.             break;
  32.          default:
  33.             printf("prob%d() does not exist.\n", menu);
  34.         }
  35.         exit(0);
  36. }
  37.  
  38.  
  39. void prob1(void)
  40. {
  41. double K[4][4] = { { 2., -4.,  1.,  0.},
  42.                     {-4.,  5., -2.,  1.},
  43.                     { 1., -2.,  6., -3.},
  44.                     { 0.,  1., -3.,  7.}};
  45. double y[4], x[4] = { 1./3., 2./3., 1./3., pow(3.,0.5)/3.};
  46. int k, rows, i;
  47. double dot_p;
  48.  
  49.  
  50. printf("\nInitial vector:\n");
  51. printf("x[0] = [" );
  52. for(rows=0; rows<4; rows++){
  53.         printf(" %f", x[rows]);
  54.         }
  55. printf("]\n");
  56. printf("\nNew Vector:\n");
  57. for(t=0; t<10; t++){
  58.         printf("y[%d] = [", t);
  59.         for(rows = 0; rows<4; rows++){
  60.                // printf(" %g", matrix_mult(double a[4][4], double b[4], double c[4], int row));
  61.         }
  62.         printf("]\n");
  63. }
  64. }
  65.  
  66.  
  67. void matrix_mult(double a[4][4], double b[4], double c[4], int row)
  68. {
  69. /* compute c[]=a[][]*b[]*/
  70. int col;
  71. double sum;
  72. for(row=0;row<4; row++){
  73.         for(col=0, sum=0.0;col<4; col++){
  74.                 sum +=a[row][col]*b[col];
  75.                 }
  76.         c[row]=sum;
  77.         }
  78. return;
  79. }
  80.  
  81. double unit_norm(double vec[4], int cols)
  82. {
  83. double sum=0;
  84. /* normalize a vector */
  85. int i;
  86. for(i=0; i<cols; i++)
  87.         sum += vec[i] * vec[i];
  88. sum = sqrt(sum);
  89. for(i=0; i<cols; i++)
  90. vec[i]=vec[i]/sum;
  91. return sum;
  92. }
Dec 6 '07 #1
2 1634
RRick
463 Expert 256MB
Before we can help you, you need to tell us what and where the problem is.

If your problem is in the printf statement (line 60) with matrix_mult, then that is not going to work. You need to pass existing arrays to matrix_mult, and then you can print out the result (i.e. c array) in the loop with the printf statement. Since matrix_mult does not return anything, you can't use it in the printf statement.
Dec 6 '07 #2
its okay i got THIS program to work but if you can check my other thread or post, that would be great.
Dec 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nils Wagner | last post by:
Hi all, Has someone written a C binding to transfer matrices from C to Python and vice versa ? Any pointer would be appreciated. Nils
4
by: Vinc_get31 | last post by:
Hi everyone! I have 2 matrices : The 1 is smaller than the 2. I would like to select in the 2nd only lines which correspond to couples of 1st... Is that possible? And how? However, I need a...
3
by: Prototipo | last post by:
Hi! I need to dynamically create X vectors of matrices (with a known size of 5x5). It's like a three-dimensional matrix with 2 known dimensions and the third unknown. I have something like: ...
7
by: Dan Trowbridge | last post by:
He everyone, I am just getting started with .NET and I am having a porting problem. I get and error in code that lookssomething like this (really stripped down but you get the idea)... class...
2
by: Chris Smith | last post by:
Howdy, I'm a college student and for one of we are writing programs to numerically compute the parameters of antenna arrays. I decided to use Python to code up my programs. Up to now I haven't...
1
emaghero
by: emaghero | last post by:
Does anybody know an algorithm for the fast multiplication of three n-x-n symmetric matrices? I have an algorithm, which I'm not too pleased with, that does the job. Does anybody know a faster...
9
by: tomamil | last post by:
imagine that you have different matrices with different names and you want to perform the same action with each of them. is it possible to put their names into some array and to create a loop that...
5
by: td0g03 | last post by:
This program adds two square matrices - Algorithm 1-3, Page 35. Change it to implement the generalized algorithm to add two m x n matrices. Matrices, in general, are not square or n x n...
3
by: nadzna | last post by:
i'm new in C++ world..i have a trouble in to solve the problem in array chapter... can someone help me how to solve this??? the QUESTION: Write a Program that calculate the 3 sum of matrices (4...
1
by: dcatunlucky | last post by:
Ok, I have an assignment to write a program that multiplies two matrices. The matrices dimensions will be user defined as well as the numbers (floating point values) inside of them. The program must...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.