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
 Origin Forum
 sum function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

sundown

UK
2 Posts

Posted - 07/09/2003 :  12:10:42 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
As a new user of origin can anyone tell me how I can formulate an expression of the type:

col(B) = sum (from j=1 to N) e to the power of |i-j|/X

where j=1 to N are the first to last values in col(A), i is the row number and X is a constant.

i.e. if col(A) =1,2,3 then
col(B)[1] = (e raised to 0)+(e raised to 1/X)+(e raised to 2/X)
col(B)[2] = (e raised to 1/X)+(e raised to 0)+(e raised to 1/X)
col(B)[3] = (e raised to 2/X)+(e raised to 1/X)+(e raised to 0)

Thanks in advance

Mike Buess

USA
3037 Posts

Posted - 07/09/2003 :  7:04:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is the slow LabTalk method...

get col(A) -e NN; // find number of rows
loop (ii,1,NN) {
col(B)[ii]=0;
loop (jj,1,NN) {
kk=abs(ii-jj);
col(B)[ii]+=exp(kk/X);
};
};

This is much faster...

get col(A) -e NN; // find number of rows
temp=data(1,NN); // create a temporary dataset
loop (ii,1,NN) {
temp=col(A);
temp-=ii;
temp=abs(temp);
temp/=X;
temp=exp(temp);
sum(temp);
col(B)[ii]=sum.total;
};
del temp;

It's even faster using the second method in an Origin C function...
void MyFunc(double dX)
{
Worksheet wks = Project.ActiveLayer();
Dataset dA(wks,0);
Dataset dB(wks,1);
int NN = dA.GetSize();
Dataset dTemp;
dTemp.Create(NN);
BasicStats bStat;
for(int i=0; i<NN; i++)
{
dTemp = dA;
dTemp -= (i+1);
dTemp = abs(dTemp);
dTemp /= dX;
dTemp = exp(dTemp);
Data_sum(&dTemp, &bStat);
dB[i] = bStat.total;
}
}


Mike Buess
Origin WebRing Member
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