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

benderrr

Germany
Posts

Posted - 05/08/2007 :  09:19:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: XP

Hi All,
I have some functions (sums of gaussians) like
functionIP1(x) = .1308231159*exp(-(x/1*ln(2))^2)+.1790045425*exp(-(x/1.2*ln(2))^2)+.1142549880*exp(-(x/1.4*ln(2))^2)+0.9617070936e-1*exp(-(x/1.2*ln(2))^2)+0.8266945293e-1*exp(-(x/1*ln(2))^2)+0.7394446425e-1*exp(-(x/0.8*ln(2))^2)+0.5294397570e-1*exp(-(x/0.8*ln(2))^2)+0.5052685721e-1*exp(-(x/0.6*ln(2))^2)+0.4340185310e-1*exp(-(x/0.5*ln(2))^2);
which I would like to plot. If I type in these functions by using the Graph/add Function Graph button and press "apply", the function is plotted alright. If I now save my project and reload it, the function is corrupted, i.e. cropped after a certain number of chars. Is the function too long? Same happens if I define this function using the script window. What can you do in order to use such long functions? I do not want to have to type/paste them each time..

Thanks and regards,
Bernhard

Mike Buess

USA
3037 Posts

Posted - 05/08/2007 :  11:05:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Bernhard,

It appears that the function expression can have no more 70 characters. Since you have O75 the easiest workaround is to write the function in Origin C and save with the project...

1. Create an OC file with the MyFunc function shown at the bottom as explained here.

2. Drag the new file from CodeBuilder's User folder to its Project folder and build again if necessary.

3. Use MyFunc as the function expression (F1(x)=MyFunc(x)). When you save the project the OC file is saved with it and will be available every time you open the project.
double MyFunc(double dX)
{
// coefficients
double d1 = 0.1308231159;
double d2 = 0.1790045425;
double d3 = 0.1142549880;
double d4 = 0.9617070936e-1;
double d5 = 0.8266945293e-1;
double d6 = 0.7394446425e-1;
double d7 = 0.5294397570e-1;
double d8 = 0.5052685721e-1;
double d9 = 0.4340185310e-1;

// function
double dY = d1*exp(-(dX/1*ln(2))^2) +
d2*exp(-(dX/1.2*ln(2))^2) + d3*exp(-(dX/1.4*ln(2))^2) +
d4*exp(-(dX/1.2*ln(2))^2) + d5*exp(-(dX/1*ln(2))^2) +
d6*exp(-(dX/0.8*ln(2))^2) + d7*exp(-(dX/0.8*ln(2))^2) +
d8*exp(-(dX/0.6*ln(2))^2) + d9*exp(-(dX/0.5*ln(2))^2);

return dY;
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 05/08/2007 11:09:02 AM
Go to Top of Page

benderrr

Germany
Posts

Posted - 05/09/2007 :  10:22:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mike,

thanks a bunch, works fine.

I am afraid I am terrible at OriginC, so could you in addition tell me how to determine the FWHM of such a function? I tried to compile the following function with Origin CodeBuilder:

#include <Origin.h>
double dWx = fwhm(MyFunc);
printf("Peak width at half maximum Y is %g", dWx);

but I get syntax error. I am aware that it might be necessary to define a Curve first, but it seems to me that the Curve cmd works with a dataset only. Since I am using a function w/o an available dataset, do I have to create a dataset first or can you skip that and directly determine the FWHM of the function?

Thanks again and best regards,

Bernhard
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 05/09/2007 :  1:00:35 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, you need to create a curve and there are two problems...

1. I can't find a way to create an Origin C curve from unattached datasets, which are datasets that are not in worksheets.
You can get around that by invoking LabTalk.

2. The fwhm function finds the width of a peak whereas your function describes a decaying exponential-like curve.
fwhm will never return a value for such a curve, i.e., fwhm(MyCrv)=--.
I think you want the X value at which Y = half maximum.

Try the following function. (If you want to try fwhm move the // from that line to the next.)
You can create a text label that runs the function with a command like this...
type -a "width: $(XatHalfMax())". (Instructions)
double XatHalfMax()
{
GraphLayer gl = Project.ActiveLayer();
DataPlot dp = gl.DataPlots(-1);
string sYname = dp.GetDatasetName();
char chX[23];
string sCmd;
sCmd.Format("%%A=xof(%s)",sYname);
gl.LT_execute(sCmd);
LT_get_str("%A",chX,23);
Worksheet wks;
wks.Create();
wks.LT_execute("col(1) = " + chX);
wks.LT_execute("col(2) = " + sYname);
Dataset dsX(wks,0);
Dataset dsY(wks,1);
Curve cc(dsX,dsY);
//double dWidth = fwhm(cc);
double dWidth = Curve_xfromY(&cc, max(cc)/2.0);
wks.Destroy();
return dWidth;
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 05/09/2007 1:09:11 PM
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