Problem with interp script on page 324 of Octave3.0.1 manual

Ben Abbott bpabbott at mac.com
Fri Aug 15 22:13:19 CDT 2008


On Aug 15, 2008, at 10:45 PM, Prof M. N. Anandaram wrote:

> Hello jwe or anyone:
> The program and the response are given below.
> Help with modification will be appreciated.
> Anandaram
> =======================================================
> % this script is from Ch.28, page 324 of GNUOctave manual:
> t = -2:2;
> dt = 1;
> ti =-2:0.025:2;
> dti = 0.025;
> y = sign(t);
> ys = interp1(t,y,ti,'spline');
> yp = interp1(t,y,ti,'pchip');
> ddys = diff(diff(ys)./dti)./dti;
> ddyp = diff(diff(yp)./dti)./dti;
> figure(2);
> plot (ti, ys,'r-', ti, yp,'g-');
> legend('spline','pchip',4);
> figure(2);
> plot (ti, ddys,'r+', ti, ddyp,'g*');
> legend('spline','pchip');
>
> %-----------------------------------------------------------------
> Octave 3.0.1 responds with this error message:
> error: __plt2vv__: vector lengths must match
> error: evaluating if command near line 59, column 3
> error: called from `__plt2vv__' in file `H:\Octave\share\octave 
> \3.0.1\m\plot\__plt2vv__.m'
> error: evaluating assignment expression near line 63, column 14
> error: evaluating if command near line 60, column 5
> error: evaluating if command near line 51, column 3
> error: called from `__plt2__' in file `H:\Octave\share\octave\3.0.1\m 
> \plot\__plt2__.m'
> error: evaluating assignment expression near line 76, column 10
> error: evaluating if command near line 75, column 4
> error: evaluating if command near line 55, column 2
> error: evaluating if command near line 54, column 7
> error: evaluating while command near line 41, column 5
> error: evaluating if command near line 28, column 3
> error: called from `__plt__' in file `H:\Octave\share\octave\3.0.1\m 
> \plot\__plt__.m'
> error: evaluating assignment expression near line 187, column 9
> error: called from `plot' in file `H:\Octave\share\octave\3.0.1\m 
> \plot\plot.m'
> error: near line 16 of file `intpol2.m'
>> Exit code: 1

Take a look at how "diff" works.

	help diff

diff(x) is equivalent to x(2:end)-x(1:end-1)

Which means that "ddys" an "ddyp" are 2 indices shorter than "ti"

In this instance you can use

	plot (ti(2:end-1), ddys,'r+', ti(2:end-1), ddyp,'g*');

The problem is evident by issuing the command ...

	whos ti ddys ddyp

Ben


More information about the Help-octave mailing list