help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Numerical Differentiation and Integration of Array Data


From: c.
Subject: Re: Numerical Differentiation and Integration of Array Data
Date: Sun, 4 Dec 2011 10:22:45 +0100

On 3 Dec 2011, at 22:14, syberraith wrote:

> Actually, I'm unsure if I could apply those simplifacations to the actual
> functions I am using.  It works well enough for a function simple as sin(a *
> t), however my function include a dynamic correction factor as well.
> 
> Perhaps you like to look over the paper I'm writing. for publication rather
> than homework, that has the full explanation of what my function are trying
> to express mathematically?
> 
> I'd be glad to give you a credit.

Although it might be more complicated to implement in case of a 
different function the algorithm should work identically.

Find below a generaliziotion of your procedure.

c.

##----------------------------------------------------------------

## algorithm parameters
n = 1000000;

## function parameters
p = 0.005;  
a = 5;      

## if you need to apply the same procedure
## to different functions you'll want to 
## make it into a function

function [f, s, s2] = process (fun, t)
  
  h = t(2) - t(1); 

  f  = diff (fun (t)) / h;
        
  ## the two computations below
  ## should give the same result
  s  = h * sum (f);
  s2 = fun (t (end)) - fun (t (1));

endfunction

## define here the function(s) you want to process
fun  = @(t)  a + sin ((2 * pi / p) * t);

## if the function is more complicated you may want to 
## use a full function definition instead
function res = funtmp (t, a, p)
  res = a + tanh ((2 * pi / p) * t);
endfunction
fun1 = @(t)  funtmp (t, a, p);

## time grid
t = linspace (0, p , n);

## process the first function
[f, s, sf] = process (fun, t);
# consisency error
err = s - sf

## process the second function
[f1, s1, sf1] = process (fun1, t);
# consisency error
err1 = s1 - sf1

reply via email to

[Prev in Thread] Current Thread [Next in Thread]