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 -
#include <stdio.h>
-
#include <math.h>
-
#include <stdlib.h>
-
#define ROWA 4
-
#define COLA 4
-
-
void prob1(void);
-
void prob2(void);
-
double unit_norm(double vec[4], int cols);
-
void matrix_mult(double a[4][4],double b[4], double c[4], int rows);
-
double unit_vec(double vec[4], int cols);
-
double pmatrix(double **A, double **B, double *a, double *b, int n);
-
-
-
-
-
double a[4][4], b[4], c[4];
-
int n=4,t, row, rows, col, cols, k;
-
-
main()
-
{
-
int menu;
-
printf("Enter the function number to execute (1-2):");
-
scanf("%d", &menu);
-
switch(menu){
-
case 1:
-
prob1();
-
break;
-
case 2:
-
prob2();
-
break;
-
default:
-
printf("prob%d() does not exist.\n", menu);
-
}
-
exit(0);
-
}
-
-
-
void prob1(void)
-
{
-
double K[4][4] = { { 2., -4., 1., 0.},
-
{-4., 5., -2., 1.},
-
{ 1., -2., 6., -3.},
-
{ 0., 1., -3., 7.}};
-
double y[4], x[4] = { 1./3., 2./3., 1./3., pow(3.,0.5)/3.};
-
int k, rows, i;
-
double dot_p;
-
-
-
printf("\nInitial vector:\n");
-
printf("x[0] = [" );
-
for(rows=0; rows<4; rows++){
-
printf(" %f", x[rows]);
-
}
-
printf("]\n");
-
printf("\nNew Vector:\n");
-
for(t=0; t<10; t++){
-
printf("y[%d] = [", t);
-
for(rows = 0; rows<4; rows++){
-
// printf(" %g", matrix_mult(double a[4][4], double b[4], double c[4], int row));
-
}
-
printf("]\n");
-
}
-
}
-
-
-
void matrix_mult(double a[4][4], double b[4], double c[4], int row)
-
{
-
/* compute c[]=a[][]*b[]*/
-
int col;
-
double sum;
-
for(row=0;row<4; row++){
-
for(col=0, sum=0.0;col<4; col++){
-
sum +=a[row][col]*b[col];
-
}
-
c[row]=sum;
-
}
-
return;
-
}
-
-
double unit_norm(double vec[4], int cols)
-
{
-
double sum=0;
-
/* normalize a vector */
-
int i;
-
for(i=0; i<cols; i++)
-
sum += vec[i] * vec[i];
-
sum = sqrt(sum);
-
for(i=0; i<cols; i++)
-
vec[i]=vec[i]/sum;
-
return sum;
-
}
2 1634
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.
its okay i got THIS program to work but if you can check my other thread or post, that would be great.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |