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
 How to run a function with vector in its argument
 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/20/2010 :  05:29:02 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.1
Operating System:7
Hi,
I am new to origin and trying to write a code that generates beta values (code attached) and store them in a column. The function is BetaXXXGraph(vector& x, vector& y, int N, int segment). After compiling the code, I do not know how to run this function in labtalk window in code builder even to know if it works since it has vector in its argument!!
The code is supposed to randomly choose some coordinated, store them in x[i] and y[j] arrays, use some external functions to calculate a quantity and then return the value. This procedure should continue several thousand times.
Any help would be really appreciated!
********************************************************************
THE CODE IS:

#include <Origin.h>

void BetaXXXGraph(vector& x, vector& y, int N, int segment)
{

int i,j,k,l;

run = 1000;

vector E(2*N+1); // initialize array with energy eigenvalues

matrix<complex> Xmoment(2*N+1,2*N+1); // initialize X position matrix

vector beta;//stores all the beta values
beta.SetSize(run);

double C = 0.0; //

x[1] = 0;
y[1] = 0;

for(k=1; k<=run; k++)//startes the code
{
for(i=2; i<=segment; i++)
{
x[i] = rnd();
y[i] = rnd();
}


for(i = 1; i < segment; i++)
{
C = C + sqrt((x[i+1]-x[i])^2 + (y[i+1]-y[i])^2); // loop length
}
C = C + sqrt((x[1]-x[segment])^2 + (y[1]-y[segment])^2); // adding the length
//of the last segment


for(i = -N; i<=N; i=i+1) //loop extends over 2N+1 state, N is # of excited states
{

E[i] = EnergyLoop(i, C);// hbar = m = 1

for(j = -N; j<=N; j=j+1)
{
Xmoment[i][j] = XnmWireLoop(x, y, i, j);
}
}

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

// Diagonal moments need ground state moment to be subtracted in
// order to calculate ReBetaSOS
{
Xmoment[i][i] = Xmoment[i][i] - Xmoment[0][0];
}

complex BetaGraph = 0.0;

for(i=-N; i<= N; i++)
{
for(j=-N; j<=N; j++)
{
if (i != 0 && j != 0)
{
BetaGraph = BetaGraph + (0.75)^(0.75) * Xmoment[0][i] * Xmoment[i][j] * Xmoment[j][0] /E[i]/E[j];
}
}
}

BetaGraph = BetaGraph.m_re;
beta[k] = BetaGraph;
}//end of for k=1,...

//*********************now we store beta values in a column*********************

//Get the first workbook's first worksheet's active layer
Worksheet wks = Project.ActiveLayer();
if( !wks )
return;

int nNumRows = run;
int nNumCols = 1;
wks.SetSize(nNumRows, nNumCols);

Column col = wks.Columns(0); //get the first column of the worksheet
if( !col )
return;

vectorbase& vb = col.GetDataObject(); //get the reference of a column

vb = beta; //set customer data,operation on vb will take effect instantly on column, or you can change elements of vb directly

return;
}

Penn

China
644 Posts

Posted - 11/21/2010 :  9:29:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please refer to this page for more details about how to use compiled OC functions.

Penn
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