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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Vector operation dimension check error (PROMPT)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

shafei

USA
49 Posts

Posted - 11/22/2010 :  5:45:56 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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!

shafei

USA
49 Posts

Posted - 11/22/2010 :  5:51:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ignore the entire YnmWireLoop part.
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 11/22/2010 :  6:11:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
} 
Go to Top of Page

shafei

USA
49 Posts

Posted - 11/22/2010 :  6:16:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for reply.
I made the changes but got the same error again!
Shoresh
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 11/22/2010 :  6:47:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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]
Go to Top of Page

shafei

USA
49 Posts

Posted - 11/22/2010 :  8:38:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for comments. the problem resolved.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000