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

jmb22

USA
Posts

Posted - 05/20/2005 :  1:07:48 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: WinXp

Hey,

I am trying to add a short script in a Origin C program. I have some difficulties with finite derivative for Cosine functions.

what method should be used to calculate analytically the derivative of a Sin function.

For polynomaial or others, I am using:
f'[x]=(f(x+h)-f(x-h))/2h with h very small

It does work well.
However, if I implement the same method for a Sin[x+c] function, the result is not consistent with what is expected.

easwar

USA
1964 Posts

Posted - 05/20/2005 :  1:52:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The method should not be sensitive to the actual function? I am not sure why this is not working for you...

I did a quick test with code pasted below and the result looks right..

Easwar
OriginLab


const double h = 0.001;

void finite_derivative()
{
WorksheetPage wpg;
wpg.Create("Origin");
Worksheet wks = wpg.Layers(0);
while( wks.DeleteCol(0) );
wks.AddCol();
wks.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
wks.AddCol();
wks.Columns(1).SetLabel("Function");
wks.AddCol();
wks.Columns(2).SetLabel("Derivative");


Dataset dsX(wks, 0);
Dataset dsY(wks, 1);
Dataset dsDY(wks, 2);

for(double x = 0; x < 10; x += 0.1)
{
dsX.Add(x);
dsY.Add(myfunc(x));
dsDY.Add(myderiv(x));
}

GraphPage gpg;
gpg.Create("Origin");
GraphLayer gly = gpg.Layers(0);
gly.AddPlot(wks);
gly.LT_execute("legend;");
gly.Rescale();
}

static double myfunc(double x)
{
return sin(x + 2.5);
}

static double myderiv(double x)
{
return ( (myfunc(x+h) - myfunc(x-h)) / (2 * h) )
}







If you are just interested in computing numerical derivatives, you do not have to write your own routine, but can use the curve_derivative() function listed under Global Functions->Analysis in the Origin C Language Reference help file.


Edited by - easwar on 05/21/2005 07:49:27 AM
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