473,387 Members | 1,693 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,387 software developers and data experts.

Problem with double matrix in vc++ Express edition

Hi, I've got a problem with this code.

I've got a double Matrix A and a vector b, initialized with

DoubleMatr A = new double*[3];
DoubleVect b = new double[3];

where DoubleMatr and DoubleVect are defined as

typedef double* DoubleVect;
typedef double** DoubleMatr;

then i pass the matrix and the vector to a function

void CreateSystemFromPolygon(Polygon *p, double *X, double *Y,
DoubleMatr A, DoubleVect b)
....
for ( int i = 0 ; i < 3 ; i++)
{
for (int j = 0 ; j < 3; j++)
{
A[i][j] = 0;
}

b[i] = 0.0;
}

A[0][0] = 1.0;
A[1][1] = 1.0;

b[0] = X[0];
b[1] = Y[0];
....

at runtime i watch the values of A[0][0] A[0][1] etc..
I see that the istruction A[0][0] = 1.0 modify A[0][0] but A[1][0] and
A[2][0] too.
Where is the problem?
Dec 20 '07 #1
4 1295
Nangi wrote:
Hi, I've got a problem with this code.

I've got a double Matrix A and a vector b, initialized with

DoubleMatr A = new double*[3];
DoubleVect b = new double[3];

where DoubleMatr and DoubleVect are defined as

typedef double* DoubleVect;
typedef double** DoubleMatr;

then i pass the matrix and the vector to a function

void CreateSystemFromPolygon(Polygon *p, double *X, double *Y,
DoubleMatr A, DoubleVect b)
...
for ( int i = 0 ; i < 3 ; i++)
{
for (int j = 0 ; j < 3; j++)
{
A[i][j] = 0;
}

b[i] = 0.0;
}

A[0][0] = 1.0;
A[1][1] = 1.0;

b[0] = X[0];
b[1] = Y[0];
...

at runtime i watch the values of A[0][0] A[0][1] etc..
I see that the istruction A[0][0] = 1.0 modify A[0][0] but A[1][0] and
A[2][0] too.
Where is the problem?
Nanji:

You have not defined a two-dimensional double array. You have just
defined an array of 3 double pointers. A[0], for example is a pointer to
double, but it is not pointing at anything. You need to do

A[0] = new double[3];
A[1] = new double[3];
A[2] = new double[3];

--
David Wilkinson
Visual C++ MVP
Dec 21 '07 #2
On 21 Dic, 03:39, David Wilkinson <no-re...@effisols.comwrote:
Nangi wrote:
Hi, I've got a problem with this code.
I've got a double Matrix A and a vector b, initialized with
* *DoubleMatr A = new double*[3];
* *DoubleVect b = new double[3];
where DoubleMatr and DoubleVect are defined as
typedef double* DoubleVect;
typedef double** DoubleMatr;
then i pass the matrix and the vector to a function
void CreateSystemFromPolygon(Polygon *p, double *X, double *Y,
DoubleMatr A, DoubleVect b)
...
* *for ( int i = 0 ; i < 3 ; i++)
* *{
* * * * * *for (int j = 0 ; j < 3; j++)
* * * * * *{
* * * * * * * * * *A[i][j] = 0;
* * * * * *}
* * * * * *b[i] = 0.0;
* *}
* *A[0][0] = 1.0;
* *A[1][1] = 1.0;
* *b[0] = X[0];
* *b[1] = Y[0];
...
at runtime i watch the values of A[0][0] A[0][1] etc..
I see that the istruction A[0][0] = 1.0 modify A[0][0] but A[1][0] and
A[2][0] too.
Where is the problem?

Nanji:

You have not defined a two-dimensional double array. You have just
defined an array of 3 double pointers. A[0], for example is a pointer to
double, but it is not pointing at anything. You need to do

A[0] = new double[3];
A[1] = new double[3];
A[2] = new double[3];

--
David Wilkinson
Visual C++ MVP- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
Sorry, I forgot to post this part of code..

for ( int i = 0 ; i < 3 ; i++ ) A[i] = new double[3];
Dec 21 '07 #3
On 21 Dic, 03:39, David Wilkinson <no-re...@effisols.comwrote:
Nangi wrote:
Hi, I've got a problem with this code.
I've got a double Matrix A and a vector b, initialized with
* *DoubleMatr A = new double*[3];
* *DoubleVect b = new double[3];
where DoubleMatr and DoubleVect are defined as
typedef double* DoubleVect;
typedef double** DoubleMatr;
then i pass the matrix and the vector to a function
void CreateSystemFromPolygon(Polygon *p, double *X, double *Y,
DoubleMatr A, DoubleVect b)
...
* *for ( int i = 0 ; i < 3 ; i++)
* *{
* * * * * *for (int j = 0 ; j < 3; j++)
* * * * * *{
* * * * * * * * * *A[i][j] = 0;
* * * * * *}
* * * * * *b[i] = 0.0;
* *}
* *A[0][0] = 1.0;
* *A[1][1] = 1.0;
* *b[0] = X[0];
* *b[1] = Y[0];
...
at runtime i watch the values of A[0][0] A[0][1] etc..
I see that the istruction A[0][0] = 1.0 modify A[0][0] but A[1][0] and
A[2][0] too.
Where is the problem?

Nanji:

You have not defined a two-dimensional double array. You have just
defined an array of 3 double pointers. A[0], for example is a pointer to
double, but it is not pointing at anything. You need to do

A[0] = new double[3];
A[1] = new double[3];
A[2] = new double[3];

--
David Wilkinson
Visual C++ MVP- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
I've tried to run same code in Borland C++ Builder 2006.
THERE IS NO ERROR!

IS THIS A VC++ 2008 BUG?
Dec 22 '07 #4
Nangi wrote:
On 21 Dic, 03:39, David Wilkinson <no-re...@effisols.comwrote:
>Nangi wrote:
>>Hi, I've got a problem with this code.
I've got a double Matrix A and a vector b, initialized with
� �DoubleMatr A = new double*[3];
� �DoubleVect b = new double[3];
where DoubleMatr and DoubleVect are defined as
typedef double* DoubleVect;
typedef double** DoubleMatr;
then i pass the matrix and the vector to a function
void CreateSystemFromPolygon(Polygon *p, double *X, double *Y,
DoubleMatr A, DoubleVect b)
...
� �for ( int i = 0 ; i < 3 ; i++)
� �{
� � � � � �for (int j = 0 ; j < 3; j++)
� � � � � �{
� � � � � � � � � �A[i][j] = 0;
� � � � � �}
� � � � � �b[i] = 0.0;
� �}
� �A[0][0] = 1.0;
� �A[1][1] = 1.0;
� �b[0] = X[0];
� �b[1] = Y[0];
...
at runtime i watch the values of A[0][0] A[0][1] etc..
I see that the istruction A[0][0] = 1.0 modify A[0][0] but A[1][0] and
A[2][0] too.
Where is the problem?
Nanji:

You have not defined a two-dimensional double array. You have just
defined an array of 3 double pointers. A[0], for example is a pointer to
double, but it is not pointing at anything. You need to do

A[0] = new double[3];
A[1] = new double[3];
A[2] = new double[3];

--
David Wilkinson
Visual C++ MVP- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

I've tried to run same code in Borland C++ Builder 2006.
THERE IS NO ERROR!

IS THIS A VC++ 2008 BUG?
Nanji:

Maybe the bug (if any) is in the debugger, not in the code generator.

--
David Wilkinson
Visual C++ MVP
Dec 22 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bonj | last post by:
Hi I installed .NET 2005 express edition, and am about to unnistall it again because it can't seem to be able to even insert a resource file into a project. Can anyone tell me is this right?...
12
by: John Gabriel | last post by:
lThe compiler output report is seldom correct: Problems here involve not being able to generate an accurate compile report. There are so many problems and I am not on Microsoft's payroll. Neither...
6
by: John Dalberg | last post by:
I don't know how much Microsoft is planning to price Visual Web Developer Express Edition. I heard rumors from free to $100. In my opinion I think it should make it free. The reason is to attract...
2
by: Vijay | last post by:
Can I write ASPX pages wtih VC# Express edition for windows? Will get a template, like New ASPX page? VJ
2
by: Ralph | last post by:
Does anyone know how to obtain the VC++ 2005 Express Edition on a CD? I have been unable to download and create a viable CD from the Microsoft site. Either not holding my mouth right or I have...
2
by: Schizoid Man | last post by:
Hi, I want to write some custom UDFs for Excel in C# and and build them into XLLs. However, I can't seem to check the Register for Com Interop box in the Express Edition of VC#. Is this a...
3
by: hsmit.home | last post by:
I spent way too much time on this and I must say, I was a little disgruntled with what has been posted on all the various Xalan C mailing lists. Everyone says there's a solution, but give next to...
9
by: =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?= | last post by:
What is the difference between the regular VC++ edition and the VC++ express edition? If there is not too much difference in functionality, why the express edition is free?
2
by: ChaosMageX | last post by:
I copied some code from a Mono 2.4 library to use in my own application. I'm getting a problem because one of the variable declarations involves the keyword "pinned" between the identifier and the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.