The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Vector operation dimension check error (PROMPT)

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
shafei Posted - 11/22/2010 : 5:45:56 PM
I have the following code

*******************************************************************
#include <Origin.h>
#include "MyFunctions.h"

#pragma labtalk(1) // Enable OC functions in LabTalk (default)

complex XnmWireLoop(vector& x, vector& y, int& p, int& q, double& C)

{

int xx = x.GetSize(); // Get x array size
int yy = y.GetSize(); // Get y array size

if (xx != yy)
{
printf("Warning, in routine RnmWireLoop.cpp, x and y arrays are not the same size");
}

complex XnmWireLoop(0.0,0.0); // Initialize XnmLoop

double length = 0.0; // Initialize loop length

int i;

for (i=1; i<=xx-1; i=i+1)

{
XnmWireLoop = XnmWireLoop + XnmWire(x[i],y[i],x[i+1],y[i+1],C,p,q,length);
// add the contribution of the ith segment to the loop

length = length + sqrt((x[i+1]-x[i])^2+(y[i+1]-y[i])^2);
// calculate cummulative length to element i
}
//printf("loop2 i=%i\n",i);

XnmWireLoop = XnmWireLoop + XnmWire(x[xx],y[xx],x[1],y[1],C,p,q,length);
// Need to add the last segment that closes the loop
// Note that variable "length" should be correct as calcualted in the last step
// of the above loop.

return XnmWireLoop;
}



// CALCULATION OF Ynm ***************************************************************

complex YnmWireLoop(vector& x, vector& y, int& p, int& q)

{

int xx = x.GetSize(); // Get x array size
int yy = y.GetSize(); // Get x array size

if (xx != yy)
{
printf("Warning, in routine RnmWireLoop.cpp, x and y arrays are not the same size");
}
/*
complex YnmWireLoop(0.0,0.0); // Initialize YnmLoop

double length = sqrt((x[0]-x[xx-1])^2+(y[0]-y[xx-1])^2); // Initialize loop length
double C = sqrt((x[0]-x[xx-1])^2+(y[0]-y[xx-1])^2); // Initialize full loop length
// This is the segment that closes the loop

int i;

for (i=0; i<=xx-2; i=i+1) // calculate full loop length

C = C + sqrt((x[i+1]-x[i])^2+(y[i+1]-y[i])^2);

for (i=0; i<=xx-2; i=i+1)

{
YnmWireLoop = YnmWireLoop + YnmWire(x[i],y[i],x[i+1],y[i+1],C,p,q,length);
// add the contribution of the ith segment to the loop

length = length + sqrt((x[i+1]-x[i])^2+(y[i+1]-y[i])^2);
// calculate cummulative length to element i
}

YnmWireLoop = YnmWireLoop + YnmWire(x[xx-1],y[xx-1],x[0],y[0],C,p,q,length);
// Need to add the last segment that closes the loop
// Note that variable "length" should be correct as calcualted in the last step
// of the above loop.

*/

return 1;
}

*******************************************************************
for which I use
dataset ds=Data(0,10,1);
dataset dt=Data(0,10,1);
M=4;N=3;C=12;
XnmWireLoop(ds, dt, M, N, C)=
where I get the error
"Vector operation dimension check error".
I am 100% sure the function XnmWire(...) is working properly! I do not understand what is wrong with my code!
5   L A T E S T    R E P L I E S    (Newest First)
shafei Posted - 11/22/2010 : 8:38:18 PM
Thanks for comments. the problem resolved.
rlewis Posted - 11/22/2010 : 6:47:05 PM
There is a problem with thisline ..


XnmWireLoop = XnmWireLoop + XnmWire(x[xx],y[xx],x[1],y[1],C,p,q,length);



Because of C indexing..
x[xx] should be x[xx-1]
y[xx] should be y[xx-1]

Also if your intent is to use the the fist element of the array
x[1] should be x[0]
y[1] should be y[0]
shafei Posted - 11/22/2010 : 6:16:32 PM
Thanks for reply.
I made the changes but got the same error again!
Shoresh
rlewis Posted - 11/22/2010 : 6:11:14 PM
Try replacing


for (i=1; i<=xx-1; i=i+1)

{ 
XnmWireLoop = XnmWireLoop + XnmWire(x[i],y[i],x[i+1],y[i+1],C,p,q,length);
// add the contribution of the ith segment to the loop

length = length + sqrt((x[i+1]-x[i])^2+(y[i+1]-y[i])^2);
// calculate cummulative length to element i
} 


with the following ...


for (i=0;i<xx-1;i++)
{ 
	XnmWireLoop = XnmWireLoop + XnmWire(x[i],y[i],x[i+1],y[i+1],C,p,q,length);
	// add the contribution of the ith segment to the loop

	length = length + sqrt((x[i+1]-x[i])^2+(y[i+1]-y[i])^2);
	// calculate cummulative length to element i
} 
shafei Posted - 11/22/2010 : 5:51:49 PM
Ignore the entire YnmWireLoop part.

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000