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
 Simulation issue

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
ase724 Posted - 10/27/2013 : 01:46:38 AM
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro9.0.0, SR2.
Operating System: Windows 7

Hi,
I wrote a simulation code for a function n1 as a function of time. I found that Origin doesn't compute all the outputs (n1). The Origin C code below only computes n1(0)~n1(10) (t = 0~10 minutes), and gives 0 for the remaining results (n1(11)~n1(99)). I use Mathematica to compute the same function with the same input parameters. Mathematica gives the same value of n1(0)~n1(10) as Origin C, and Mathematica also computes other values (n1(11)~n1(99)) which are not zero. What is the reason causing Origin C to return 0 for some results?

Origin C code:

void NofT()
{
double a = 2.18;
double b = 0.656;
double airr = 9.982E-7;
double Ip = 30;
int time = 100; // min., total time.
int tcount = 100;
double dt = time/tcount;

double ma = b+(a+airr)*Ip;
double mc = b+(a-airr)*Ip;
double mb = sqrt((b+(a+airr)*Ip)^2-4*b*airr*Ip);

vector vt;
vt = TimeAxis(tcount, dt);
vector n1;
n1.SetSize(tcount);

for(int tt = 0; tt < tcount; tt++)
{
n1[tt] = ((mb-mc)*(mb+mc)*(exp(mb*vt[tt])-1)*exp(-0.5*(ma+mb)*vt[tt]))/(2*mb*(ma-mc));
printf("n1[%d]=%f\n",tt ,n1[tt]);
}
}

vector TimeAxis(int tcount, double dt)
{
vector vt;
vt.SetSize(tcount);
for (int tt = 0; tt < tcount; tt++)
{
vt[tt] = tt*dt; // t axis, min.
}
return (vt);
}

4   L A T E S T    R E P L I E S    (Newest First)
ase724 Posted - 11/06/2013 : 5:55:37 PM
Thanks again, rlewis! This is very helpful for me!
rlewis Posted - 10/27/2013 : 6:21:37 PM
The following is a recoded version of your function to avoid the exponential oveflow problem ...

void NofT()
{
	double a = 2.18;
	double b = 0.656;
	double airr = 9.982E-7;
	double Ip = 30;
	int time = 100; // min., total time.
	int tcount = 100;
	double dt = time/tcount;

	double ma = b+(a+airr)*Ip;
	double mc = b+(a-airr)*Ip;
	double mb = sqrt((b+(a+airr)*Ip)^2.0 - (4.0*b*airr*Ip));
	
	double Phi=((mb-mc)*(mb+mc))/(2.0*mb*(ma-mc));
	double lnPhi=ln(Phi);
	
	vector<double> vt;
	vt.Data(0,((tcount-1)*dt),dt);

	vector<double> n1;
	n1.SetSize(vt.GetSize());

	double 	Lna, Lnb;
	for(int tt = 0; tt < tcount; tt++)
	{
		if((mb*vt[tt] < 665.0) || ((ma+mb)*vt[tt] < 665.0))
		{
			n1[tt] = Phi*((exp(mb*vt[tt])-1.0)*exp(-0.5*(ma+mb)*vt[tt]));
			printf("n1[%d]=%f\n",tt ,n1[tt]);
		}
		else
		{
			Lna=mb*vt[tt];
			Lnb=-0.5*(ma+mb)*vt[tt];
			n1[tt]=exp(lnPhi+Lna+Lnb);
			printf("n1[%d]=%f\n",tt ,n1[tt]);
		}
	}
}
ase724 Posted - 10/27/2013 : 1:51:26 PM
Thank you, rlewis! The exponential terms are indeed overflowing which causes the zero values.
rlewis Posted - 10/27/2013 : 03:32:47 AM
I think one of the exponential terms in your function overflows ...
Try recoding you function ....

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