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
 Origin Forum
 Finite derivative

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
jmb22 Posted - 05/20/2005 : 1:07:48 PM
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.

1   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 05/20/2005 : 1:52:36 PM
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

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