[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multi Column Data file to plot, gradient plot, or gradient of gradie
From: |
Henry F. Mollet |
Subject: |
Re: Multi Column Data file to plot, gradient plot, or gradient of gradient plot |
Date: |
Tue, 30 Mar 2004 16:27:04 -0800 |
User-agent: |
Microsoft-Entourage/10.1.1.2418 |
octave:62> filter([-1,1],1,y) ./ filter([-1,1],1,x)
error: invalid conversion from matrix to real vector
error: filter: arguments must be vectors
error: evaluating binary operator `./' near line 62, column 20
I don't understand why the PK suggestion should not be a reasonable first
approximation for the first derivative. repmat(diff(x),1,columns(y)) creates
a matrix of the same size as diff(y) holding diff (x) as often as needed
(columns of y). I agree that it would be better to plot the first
derivative at "x+0.5" if the x's are one unit apart. However, if the
y-values are functions of x, then one could create an x-vector of a
sufficiently large size, so that (x at i+1 - x at i) is as small as needed
and then one could plot the 1st derivative at x instead of at "x+0.5 units"?
Henry
on 3/30/04 1:27 PM, Przemek Klosowski at address@hidden wrote:
> On Mar 26, 2004, at 1:39 PM, Timothy Milstead wrote:
>
>> xy plot the gradient of the data as lines and then finally the
>> gradient of the gradient as xy plot.
>
> And Paul Kienzle suggested:
>
> This is the simple formula for a gradient,
>
> dy/dx ~= (y_i+1 - y_i) / (x_i+1 - x_i)
> d2y/dx2 ~= (y_i+1 - 2y_i - y_i-1) / (x_i+1 - x_i)^2
>
> You can come up with more sophisticated approximations.
>
> and came up with this implementation
>
> plot(x(1:end-1),diff(y)./repmat(diff(x),1,columns(y)));
> plot(x(2:end-1),diff(y,2)./repmat(diff(x(2:end)).^2,1,columns(y)));
>
> OK, so we have relatively simple formulas, and an implementation that
> is not only nonobvious, but I think might also be incorrect.
>
> At first, I thought that there should be built-in differential
> operators (gradients, Laplacians, etc), but then, I thought that there
> are multiple details---possibly higher-order corrections, etc, that
> would be hard to provide in a simple and general way. Then, it
> occurred to me that the 'filter()' function is great for constructing
> differential operators. For instance,
>
> dydx = filter([-1,1],1,y) ./ filter([-1,1],1,x)
>
> d2ydx2 = filter ([1,-2,1],1,y) ./ filter ([1,-2,1],1,x)
>
> (I gloss over what are the values of X that I calculate the derivatives
> in, but you get the general drift).
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web: http://www.octave.org
> How to fund new projects: http://www.octave.org/funding.html
> Subscription information: http://www.octave.org/archive.html
> -------------------------------------------------------------
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------