![]() |
|
#1
|
|||
|
|||
Problem multiplying arraysHello,
I have what seems to be a really simple problem, but I've been unable to solve it in two days. I need to do the following: Find the autocorrelation of an array, which is part of a two-dimensional array. The array is of type "double", and is of length 512. When I print the arrays, SegmentArray[0][256+j] and SegmentArray[0][i+j], I get the correct values. However, when I print AutocorrArray, which should be nothing but a sum of products as described in the code below, all I get is 0. This is not the correct answer for the array in question, as has been verified by Matlab and Mathcad. What am I doing wrong? Thank you, CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
|
Quote:
What is the type of variable Sum? Post a program showing declarations. Dave |
|
#3
|
|||
|
|||
|
Quote:
CPP / C++ / C Code:
My problem is that the contents of AutocorrArray are ALL 0. Last edited by dsmith : 29-Mar-2004 at 15:08.
Reason: Fixed C syntax tag
|
|
#4
|
|||
|
|||
|
Could you supply (attach) the WaveData.txt file that you are using?
Dave |
|
#5
|
|||
|
|||
|
Quote:
You have the following: CPP / C++ / C Code:
but InputArray is declared CPP / C++ / C Code:
So fscanf() should use "%lf", I think. Are you sure you have read the input correctly? Hint: try printing out the first 10 or so (no need to print the entire array). Dave |
|
#6
|
|||
|
|||
|
Quote:
Here it is! Thanks, Dave. |
|
#7
|
|||
|
|||
|
Quote:
The input's been read correctly. I used both %f and %d, and verified (both by printing to the screen and to an output file) that the contents of InputArray are the same as "WaveData.txt". |
|
#8
|
|||
|
|||
|
Quote:
DAVE, YOU ROCK! I changed all the %ds to %lf, and I got it! What exactly is %lf anyway? Sorry, I'm a newbie! Thanks a lot! |
|
#9
|
|||
|
|||
|
Quote:
You declare InputArray as double so you must (must) use %lf in scanf(), not %d, not %f. Also in your printf() statements for SegmentArray and AutocorrArray, you must not use %d (OK to use %f or %lf in printf(), since the argument will be promoted to double, anyhow. For scanf(), must use %lf.) Please run again, and put the following after you close WaveData.txt: CPP / C++ / C Code:
Dave |
|
#10
|
|||
|
|||
|
Quote:
You are giving scanf() the address of a variable. Scanf() will convert the appropriate number of input bytes and store in the place you tell it. %f indicates to scanf that this is a float type variable. %lf indicates to scanf() that this is a double type variable (lf is mnemonic for "long float", I guess). By the way, C does all internal float math operations as double, so there's no advantage to float (as opposed to double), unless there are large arrays and storage becomes an issue. Regards, Dave |
Recent GIDBlog
Developing GUIs with wxPython (Part 2) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with php5 cgi installation | fab13 | Apache Web Server Forum | 3 | 19-Nov-2003 09:11 |
| unwanted scrollbar problem | kelly001 | Web Design Forum | 3 | 24-Oct-2003 10:44 |
| Geforce FX 5600 Ultra problem | jenovasbirth | Computer Hardware Forum | 1 | 04-Oct-2003 17:00 |
| folder problem in trees | zuzupus | MySQL / PHP Forum | 23 | 26-Sep-2003 07:32 |
| link problem [1][2]----- | zuzupus | MySQL / PHP Forum | 0 | 16-Sep-2003 05:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The