Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have an array of values with some calculations within the initializer. If I do the division only everything is ok, but as soon as I add multiplication and addition everting goes wrong:

C#
double x1 = 342523d / 518400d;
double[,] cornerD1 = new double[] {
    { -21600d / 13649d, (43200d / 13649d * x1 - 7624d / 40947d), -172800d / 13649d * x1 + 715489d/ 81894d, 259200d / 13649d * x1 - 187917d / 13649d, -172800d / 13649d * x1 + 735635d / 81894d, 43200d / 13649d * x1 - 89387d / 40947d, 0d, 0d, 0d },
{ -8640d / 12013d * x1 + 7624d / 180195d, 0d, 86400d / 12013d * x1 - 57139d / 12013d, -172800d / 12013d * x1 + 745733d / 72078d, 129600d / 12013d * x1 - 91715d / 12013d, -34560d / 12013d * x1 + 240569d / 120130d, 0d, 0d, 0d},
{ 17280d / 2711d * x1 - 715489d / 162660d, -43200d / 2711d * x1 + 57139d / 5422d, 0,86400d / 2711d * x1 - 176839d / 8133d, -86400d / 2711d * x1 + 242111d / 10844d, 25920d / 2711d * x1 - 182261d / 27110d, 0d, 0d, 0d},
{ -25920d / 5359d * x1 + 187917d / 53590d, 86400d / 5359d * x1 - 745733d / 64308d, -86400d / 5359d * x1 + 176839d / 16077d, 0d, 43200d / 5359d * x1 - 165041d / 32154d, -17280d / 5359d * x1 + 710473d / 321540d, 72d / 5359d, 0d, 0d},
{ 34560d / 7877d * x1 - 147127d / 47262d, -129600d / 7877d * x1 + 91715d / 7877d, 172800d / 7877d * x1 - 242111d / 15754d, -86400d / 7877d * x1 + 165041d / 23631d, 0d, 8640d / 7877d * x1, -1296d / 7877d, 144d / 7877d, 0d},
{ -43200d / 43801d * x1 + 89387d / 131403d, 172800d / 43801d * x1 - 240569d / 87602d, -259200d / 43801d * x1 + 182261d / 43801d,172800d / 43801d * x1 - 710473d / 262806d, -43200d / 43801d * x1, 0, 32400d / 43801d, -6480d / 43801d,720d / 43801d} };


What I have tried:

Do I really have to set up each element after the calculation? Is there no other way?

Code is ported from Octave were this is possible.
Posted
Updated 5-Apr-23 0:32am

1 solution

Wrong type:
C#
double[,] cornerD1 = new double[] { ...
Should be
C#
double[,] cornerD1 = new double[,] { ...
                                ^
                                |
Without the extra dimension, it doesn't know what you are trying to do and you get an error with the initializer.
 
Share this answer
 
v2
Comments
Kenneth Haugland 5-Apr-23 6:33am    
Dang... I saw it just now as well...
OriginalGriff 5-Apr-23 6:35am    
Easy mistake to make - I read what I meant to write as well ... :O
Richard Deeming 5-Apr-23 8:23am    
Or, in any relatively-recent version of C#, simply omit the new keyword and type specification[^]:
double[,] cornerD1 = { ... };

:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900