ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vspline.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2009-2012 ADMB Foundation
6  */
13 #include <fvar.hpp>
14 
15 dvar_vector spline(const dvector &x,const dvar_vector&y,double yp1,double ypn);
16 dvar_vector spline(const dvector &x,const dvar_vector&y,dvariable yp1,
17  dvariable ypn);
18 dvariable spline_cubic_val2(int n, const dvector& t, const prevariable& tval,
19  const dvar_vector& y, const dvar_vector& ypp);
20 dvariable spline_cubic_val(int n, const dvector& t, double tval,
21  const dvar_vector& y, const dvar_vector& ypp);
22 
23 dvar_vector spline_cubic_set (int n, const dvector& t, const dvar_vector& y,
24  int ibcbeg, dvariable ybcbeg, int ibcend, dvariable ybcend );
25 
38 dvariable splint(const dvector& _xa,const dvar_vector& _ya,
39  const dvar_vector& _y2a,double x)
40 {
43  dvariable ret = spline_cubic_val(_xa.size(), _xa, x, _ya, _y2a);
45  return ret;
46 }
47 
57 dvariable splint(const dvector& _xa,const dvar_vector& _ya,
58  const dvar_vector& _y2a, const prevariable& _x)
59 {
62  dvariable ret = spline_cubic_val2(_xa.size(), _xa, _x, _ya, _y2a);
64  return ret;
65 }
66 
72  const dvar_vector& _y,dvariable yp1,dvariable ypn) : x(_x) , y(_y)
73 {
74  y2.allocate(x);
75  y2=spline(x,y,yp1,ypn);
76 }
77 
83  const dvar_vector& _y,double yp1,double ypn) : x(_x) , y(_y)
84 {
85  y2.allocate(x);
86  y2=spline(x,y,yp1,ypn);
87 }
88 
94 {
95  // need to deal with u<x(1) or u>x(2)
96  return splint(x,y,y2,u);
97 }
98 
104 {
105  int mmin=u.indexmin();
106  int mmax=u.indexmax();
107  dvar_vector z(mmin,mmax);
108  for (int i=mmin;i<=mmax;i++)
109  {
110  z(i)=splint(x,y,y2,u(i));
111  }
112  return z;
113 }
114 
120 {
121  int mmin=u.indexmin();
122  int mmax=u.indexmax();
123  dvar_vector z(mmin,mmax);
124  for (int i=mmin;i<=mmax;i++)
125  {
126  z(i)=splint(x,y,y2,u(i));
127  }
128  return z;
129 }
130 
143  dvariable ypn)
144 {
145  int ibcbeg, ibcend;
146  dvariable ybcbeg, ybcend;
147  dvector x = _x;
148  x.shift(0);
149  dvar_vector y = _y;
150  y.shift(0);
151  if(value(yp1) > 0.99e30 )
152  {
153  ibcbeg = 2;
154  ybcbeg = 0.0;
155  }
156  else
157  {
158  ibcbeg = 1;
159  ybcbeg = yp1;
160  }
161  if(value(ypn) > 0.99e30 )
162  {
163  ibcend = 2;
164  ybcend = 0.0;
165  }
166  else
167  {
168  ibcend = 1;
169  ybcend = ypn;
170  }
171 
172  dvar_vector ret = spline_cubic_set(x.size(), x, y, ibcbeg, ybcbeg, ibcend,
173  ybcend);
174  ret.shift(_x.indexmin());
175  return ret;
176 }
177 
189 dvar_vector spline(const dvector &_x,const dvar_vector&_y,double yp1,
190  double ypn)
191 {
192  int ibcbeg, ibcend;
193  dvariable ybcbeg, ybcend;
194  dvector x = _x;
195  x.shift(0);
196  dvar_vector y = _y;
197  y.shift(0);
198  if(yp1 > 0.99e30 )
199  {
200  ibcbeg = 2;
201  ybcbeg = 0.0;
202  }
203  else
204  {
205  ibcbeg = 1;
206  ybcbeg = yp1;
207  }
208  if(ypn > 0.99e30 )
209  {
210  ibcend = 2;
211  ybcend = 0.0;
212  }
213  else
214  {
215  ibcend = 1;
216  ybcend = ypn;
217  }
218 
219  dvar_vector ret = spline_cubic_set(x.size(), x, y, ibcbeg, ybcbeg, ibcend,
220  ybcend);
221  ret.shift(_x.indexmin());
222  return ret;
223 }
224 
237  double ypn)
238 {
239  int ibcbeg, ibcend;
240  dvariable ybcbeg, ybcend;
241  dvector x = _x;
242  x.shift(0);
243  dvar_vector y = _y;
244  y.shift(0);
245  if(value(yp1) > 0.99e30 )
246  {
247  ibcbeg = 2;
248  ybcbeg = 0.0;
249  }
250  else
251  {
252  ibcbeg = 1;
253  ybcbeg = yp1;
254  }
255  if(ypn > 0.99e30 )
256  {
257  ibcend = 2;
258  ybcend = 0.0;
259  }
260  else
261  {
262  ibcend = 1;
263  ybcend = ypn;
264  }
265 
266  dvar_vector ret = spline_cubic_set(x.size(), x, y, ibcbeg, ybcbeg, ibcend,
267  ybcend);
268  ret.shift(_x.indexmin());
269  return ret;
270 }
271 
284 dvariable spline_cubic_val(int n, const dvector& _t, double tval,
285  const dvar_vector& _y, const dvar_vector& _ypp)
286 //
287 // Purpose:
288 //
289 // SPLINE_CUBIC_VAL evaluates a piecewise cubic spline at a point.
290 //
291 // Discussion:
292 //
293 // SPLINE_CUBIC_SET must have already been called to define the values of
294 // YPP.
295 //
296 // For any point T in the interval T(IVAL), T(IVAL+1), the form of
297 // the spline is
298 //
299 // SPL(T) = A
300 // + B * ( T - T(IVAL) )
301 // + C * ( T - T(IVAL) )**2
302 // + D * ( T - T(IVAL) )**3
303 //
304 // Here:
305 // A = Y(IVAL)
306 // B = ( Y(IVAL+1) - Y(IVAL) ) / ( T(IVAL+1) - T(IVAL) )
307 // - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * ( T(IVAL+1) - T(IVAL) ) / 6
308 // C = YPP(IVAL) / 2
309 // D = ( YPP(IVAL+1) - YPP(IVAL) ) / ( 6 * ( T(IVAL+1) - T(IVAL) ) )
310 //
311 // Licensing:
312 //
313 // This code is distributed under the GNU LGPL license.
314 //
315 // Modified:
316 //
317 // 04 February 1999
318 //
319 // Author:
320 //
321 // John Burkardt
322 //
323 // Modified By:
324 //
325 // Derek Seiple (20 August 2010)
326 //
327 // Parameters:
328 //
329 // Input, int N, the number of knots.
330 //
331 // Input, double Y[N], the data values at the knots.
332 //
333 // Input, double T[N], the knot values.
334 //
335 // Input, double TVAL, a point, typically between T[0] and T[n-1], at
336 // which the spline is to be evalulated. If TVAL lies outside
337 // this range, extrapolation is used.
338 //
339 // Input, double YPP[N], the second derivatives of the spline at
340 // the knots.
341 //
342 // Output, double SPLINE_VAL, the value of the spline at TVAL.
343 //
344 {
345  dvariable dt = 0.0;
346  dvariable h = 0.0;
347  int i = 0;
348  int ival = 0;
349  dvariable yval = 0.0;
350  dvector& t = (dvector&)_t;
351  int lbt = t.indexmin();
352  t.shift(0);
353  dvar_vector& y = (dvar_vector&)_y;
354  int lby = y.indexmin();
355  y.shift(0);
356  dvar_vector& ypp = (dvar_vector&)_ypp;
357  int lbypp = ypp.indexmin();
358  ypp.shift(0);
359 
360  // Determine the interval [ T(I), T(I+1) ] that contains TVAL.
361  // Values below T[0] or above T[N-1] use extrapolation.
362  ival = n - 2;
363 
364  for ( i = 0; i < n-1; i++ )
365  {
366  if ( tval < t[i+1] )
367  {
368  ival = i;
369  break;
370  }
371  }
372 
373  // In the interval I, the polynomial is in terms of a normalized
374  // coordinate between 0 and 1.
375  dt = tval - t[ival];
376  h = t[ival+1] - t[ival];
377 
378  yval = y[ival]
379  + dt * ( ( y[ival+1] - y[ival] ) / h
380  - ( ypp[ival+1] / 6.0 + ypp[ival] / 3.0 ) * h
381  + dt * ( 0.5 * ypp[ival]
382  + dt * ( ( ypp[ival+1] - ypp[ival] ) / ( 6.0 * h ) ) ) );
383 
384  /* *ypval = ( y[ival+1] - y[ival] ) / h
385  - ( ypp[ival+1] / 6.0 + ypp[ival] / 3.0 ) * h
386  + dt * ( ypp[ival]
387  + dt * ( 0.5 * ( ypp[ival+1] - ypp[ival] ) / h ) );
388 
389  *yppval = ypp[ival] + dt * ( ypp[ival+1] - ypp[ival] ) / h;*/
390  t.shift(lbt);
391  y.shift(lby);
392  ypp.shift(lbypp);
393 
394  return yval;
395 }
396 
409 dvariable spline_cubic_val2(int n, const dvector& _t, const prevariable& tval,
410  const dvar_vector& _y, const dvar_vector& _ypp)
411 //
412 // Purpose:
413 //
414 // SPLINE_CUBIC_VAL evaluates a piecewise cubic spline at a point.
415 //
416 // Discussion:
417 //
418 // SPLINE_CUBIC_SET must have already been called to define the values of
419 // YPP.
420 //
421 // For any point T in the interval T(IVAL), T(IVAL+1), the form of
422 // the spline is
423 //
424 // SPL(T) = A
425 // + B * ( T - T(IVAL) )
426 // + C * ( T - T(IVAL) )**2
427 // + D * ( T - T(IVAL) )**3
428 //
429 // Here:
430 // A = Y(IVAL)
431 // B = ( Y(IVAL+1) - Y(IVAL) ) / ( T(IVAL+1) - T(IVAL) )
432 // - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * ( T(IVAL+1) - T(IVAL) ) / 6
433 // C = YPP(IVAL) / 2
434 // D = ( YPP(IVAL+1) - YPP(IVAL) ) / ( 6 * ( T(IVAL+1) - T(IVAL) ) )
435 //
436 // Licensing:
437 //
438 // This code is distributed under the GNU LGPL license.
439 //
440 // Modified:
441 //
442 // 04 February 1999
443 //
444 // Author:
445 //
446 // John Burkardt
447 //
448 // Modified By:
449 //
450 // Derek Seiple (20 August 2010)
451 //
452 // Parameters:
453 //
454 // Input, int N, the number of knots.
455 //
456 // Input, double Y[N], the data values at the knots.
457 //
458 // Input, double T[N], the knot values.
459 //
460 // Input, double TVAL, a point, typically between T[0] and T[n-1], at
461 // which the spline is to be evalulated. If TVAL lies outside
462 // this range, extrapolation is used.
463 //
464 // Input, double YPP[N], the second derivatives of the spline at
465 // the knots.
466 //
467 // Output, double SPLINE_VAL, the value of the spline at TVAL.
468 //
469 {
470  dvariable dt = 0.0;
471  dvariable h = 0.0;
472  int i = 0;
473  int ival = 0;
474  dvariable yval = 0.0;
475  dvector& t = (dvector&)_t;
476  int lbt = t.indexmin();
477  t.shift(0);
478  dvar_vector& y = (dvar_vector&)_y;
479  int lby = y.indexmin();
480  y.shift(0);
481  dvar_vector& ypp = (dvar_vector&)_ypp;
482  int lbypp = ypp.indexmin();
483  ypp.shift(0);
484 
485  // Determine the interval [ T(I), T(I+1) ] that contains TVAL.
486  // Values below T[0] or above T[N-1] use extrapolation.
487  ival = n - 2;
488 
489  for ( i = 0; i < n-1; i++ )
490  {
491  if ( tval < t[i+1] )
492  {
493  ival = i;
494  break;
495  }
496  }
497 
498  // In the interval I, the polynomial is in terms of a normalized
499  // coordinate between 0 and 1.
500  dt = tval - t[ival];
501  h = t[ival+1] - t[ival];
502 
503  yval = y[ival]
504  + dt * ( ( y[ival+1] - y[ival] ) / h
505  - ( ypp[ival+1] / 6.0 + ypp[ival] / 3.0 ) * h
506  + dt * ( 0.5 * ypp[ival]
507  + dt * ( ( ypp[ival+1] - ypp[ival] ) / ( 6.0 * h ) ) ) );
508 
509  /* *ypval = ( y[ival+1] - y[ival] ) / h
510  - ( ypp[ival+1] / 6.0 + ypp[ival] / 3.0 ) * h
511  + dt * ( ypp[ival]
512  + dt * ( 0.5 * ( ypp[ival+1] - ypp[ival] ) / h ) );
513 
514  *yppval = ypp[ival] + dt * ( ypp[ival+1] - ypp[ival] ) / h;*/
515  t.shift(lbt);
516  y.shift(lby);
517  ypp.shift(lbypp);
518 
519  return yval;
520 }
521 
530 dvar_vector d3_np_fs ( int n, const dvar_vector& _a, const dvar_vector& _b)
531 //
532 // Purpose:
533 //
534 // D3_NP_FS factors and solves a D3 system.
535 //
536 // Discussion:
537 //
538 // The D3 storage format is used for a tridiagonal matrix.
539 // The superdiagonal is stored in entries (1,2:N), the diagonal in
540 // entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the
541 // original matrix is "collapsed" vertically into the array.
542 //
543 // This algorithm requires that each diagonal entry be nonzero.
544 // It does not use pivoting, and so can fail on systems that
545 // are actually nonsingular.
546 //
547 // Example:
548 //
549 // Here is how a D3 matrix of order 5 would be stored:
550 //
551 // * A12 A23 A34 A45
552 // A11 A22 A33 A44 A55
553 // A21 A32 A43 A54 *
554 //
555 // Licensing:
556 //
557 // This code is distributed under the GNU LGPL license.
558 //
559 // Modified:
560 //
561 // 15 November 2003
562 //
563 // Author:
564 //
565 // John Burkardt
566 //
567 // Modified By:
568 //
569 // Derek Seiple (20 August 2010)
570 //
571 // Parameters:
572 //
573 // Input, int N, the order of the linear system.
574 //
575 // Input/output, double A[3*N].
576 // On input, the nonzero diagonals of the linear system.
577 // On output, the data in these vectors has been overwritten
578 // by factorization information.
579 //
580 // Input, double B[N], the right hand side.
581 //
582 // Output, double D3_NP_FS[N], the solution of the linear system.
583 // This is NULL if there was an error because one of the diagonal
584 // entries was zero.
585 //
586 {
589  int i;
590  dvariable xmult;
591 
592  // Check.
593  for ( i = 0; i < n; i++ )
594  {
595  if ( a[1+i*3] == 0.0 )
596  {
597  return NULL;
598  }
599  }
600  dvar_vector x(0,n-1);
601 
602  for ( i = 0; i < n; i++ )
603  {
604  x[i] = b[i];
605  }
606 
607  for ( i = 1; i < n; i++ )
608  {
609  xmult = a[2+(i-1)*3] / a[1+(i-1)*3];
610  a[1+i*3] = a[1+i*3] - xmult * a[0+i*3];
611  x[i] = x[i] - xmult * x[i-1];
612  }
613 
614  x[n-1] = x[n-1] / a[1+(n-1)*3];
615  for ( i = n-2; 0 <= i; i-- )
616  {
617  x[i] = ( x[i] - a[0+(i+1)*3] * x[i+1] ) / a[1+i*3];
618  }
619 
620  return x;
621 }
622 
643 dvar_vector spline_cubic_set (int n, const dvector& t, const dvar_vector& y,
644  int ibcbeg, dvariable ybcbeg, int ibcend, dvariable ybcend )
645 //
646 // Purpose:
647 //
648 // SPLINE_CUBIC_SET computes the second derivatives of a piecewise cubic
649 // spline.
650 //
651 // Discussion:
652 //
653 // For data interpolation, the user must call SPLINE_SET to determine
654 // the second derivative data, passing in the data to be interpolated,
655 // and the desired boundary conditions.
656 //
657 // The data to be interpolated, plus the SPLINE_SET output, defines
658 // the spline. The user may then call SPLINE_VAL to evaluate the
659 // spline at any point.
660 //
661 // The cubic spline is a piecewise cubic polynomial. The intervals
662 // are determined by the "knots" or abscissas of the data to be
663 // interpolated. The cubic spline has continous first and second
664 // derivatives over the entire interval of interpolation.
665 //
666 // For any point T in the interval T(IVAL), T(IVAL+1), the form of
667 // the spline is
668 //
669 // SPL(T) = A(IVAL)
670 // + B(IVAL) * ( T - T(IVAL) )
671 // + C(IVAL) * ( T - T(IVAL) )**2
672 // + D(IVAL) * ( T - T(IVAL) )**3
673 //
674 // If we assume that we know the values Y(*) and YPP(*), which represent
675 // the values and second derivatives of the spline at each knot, then
676 // the coefficients can be computed as:
677 //
678 // A(IVAL) = Y(IVAL)
679 // B(IVAL) = ( Y(IVAL+1) - Y(IVAL) ) / ( T(IVAL+1) - T(IVAL) )
680 // - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * ( T(IVAL+1) - T(IVAL) ) / 6
681 // C(IVAL) = YPP(IVAL) / 2
682 // D(IVAL) = ( YPP(IVAL+1) - YPP(IVAL) ) / ( 6 * ( T(IVAL+1) - T(IVAL) ) )
683 //
684 // Since the first derivative of the spline is
685 //
686 // SPL'(T) = B(IVAL)
687 // + 2 * C(IVAL) * ( T - T(IVAL) )
688 // + 3 * D(IVAL) * ( T - T(IVAL) )**2,
689 //
690 // the requirement that the first derivative be continuous at interior
691 // knot I results in a total of N-2 equations, of the form:
692 //
693 // B(IVAL-1) + 2 C(IVAL-1) * (T(IVAL)-T(IVAL-1))
694 // + 3 * D(IVAL-1) * (T(IVAL) - T(IVAL-1))**2 = B(IVAL)
695 //
696 // or, setting H(IVAL) = T(IVAL+1) - T(IVAL)
697 //
698 // ( Y(IVAL) - Y(IVAL-1) ) / H(IVAL-1)
699 // - ( YPP(IVAL) + 2 * YPP(IVAL-1) ) * H(IVAL-1) / 6
700 // + YPP(IVAL-1) * H(IVAL-1)
701 // + ( YPP(IVAL) - YPP(IVAL-1) ) * H(IVAL-1) / 2
702 // =
703 // ( Y(IVAL+1) - Y(IVAL) ) / H(IVAL)
704 // - ( YPP(IVAL+1) + 2 * YPP(IVAL) ) * H(IVAL) / 6
705 //
706 // or
707 //
708 // YPP(IVAL-1) * H(IVAL-1) + 2 * YPP(IVAL) * ( H(IVAL-1) + H(IVAL) )
709 // + YPP(IVAL) * H(IVAL)
710 // =
711 // 6 * ( Y(IVAL+1) - Y(IVAL) ) / H(IVAL)
712 // - 6 * ( Y(IVAL) - Y(IVAL-1) ) / H(IVAL-1)
713 //
714 // Boundary conditions must be applied at the first and last knots.
715 // The resulting tridiagonal system can be solved for the YPP values.
716 //
717 // Licensing:
718 //
719 // This code is distributed under the GNU LGPL license.
720 //
721 // Modified:
722 //
723 // 06 February 2004
724 //
725 // Author:
726 //
727 // John Burkardt
728 //
729 // Modified By:
730 //
731 // Derek Seiple (20 August 2010)
732 //
733 // Parameters:
734 //
735 // Input, int N, the number of data points. N must be at least 2.
736 // In the special case where N = 2 and IBCBEG = IBCEND = 0, the
737 // spline will actually be linear.
738 //
739 // Input, double T[N], the knot values, that is, the points were data is
740 // specified. The knot values should be distinct, and increasing.
741 //
742 // Input, double Y[N], the data values to be interpolated.
743 //
744 // Input, int IBCBEG, left boundary condition flag:
745 // 0: the cubic spline should be a quadratic over the first interval;
746 // 1: the first derivative at the left endpoint should be YBCBEG;
747 // 2: the second derivative at the left endpoint should be YBCBEG.
748 //
749 // Input, double YBCBEG, the values to be used in the boundary
750 // conditions if IBCBEG is equal to 1 or 2.
751 //
752 // Input, int IBCEND, right boundary condition flag:
753 // 0: the cubic spline should be a quadratic over the last interval;
754 // 1: the first derivative at the right endpoint should be YBCEND;
755 // 2: the second derivative at the right endpoint should be YBCEND.
756 //
757 // Input, double YBCEND, the values to be used in the boundary
758 // conditions if IBCEND is equal to 1 or 2.
759 //
760 // Output, double SPLINE_CUBIC_SET[N], the second derivatives of the cubic
761 // spline.
762 //
763 {
764  dvar_vector a(0,3*n-1);
765  dvar_vector b(0,n-1);
766  int i;
767 
768  // Check.
769  if ( n <= 1 )
770  {
771  cout << "\n";
772  cout << "SPLINE_CUBIC_SET - Fatal error!\n";
773  cout << " The number of data points N must be at least 2.\n";
774  cout << " The input value is " << n << ".\n";
775  //return NULL;
776  }
777 
778  for ( i = 0; i < n - 1; i++ )
779  {
780  if ( t[i+1] <= t[i] )
781  {
782  cout << "\n";
783  cout << "SPLINE_CUBIC_SET - Fatal error!\n";
784  cout << " The knots must be strictly increasing, but\n";
785  cout << " T(" << i << ") = " << t[i] << "\n";
786  cout << " T(" << i+1 << ") = " << t[i+1] << "\n";
787  }
788  }
789 
790  // Set up the first equation.
791  if ( ibcbeg == 0 )
792  {
793  b[0] = 0.0;
794  a[1+0*3] = 1.0;
795  a[0+1*3] = -1.0;
796  }
797  else if ( ibcbeg == 1 )
798  {
799  b[0] = ( y[1] - y[0] ) / ( t[1] - t[0] ) - ybcbeg;
800  a[1+0*3] = ( t[1] - t[0] ) / 3.0;
801  a[0+1*3] = ( t[1] - t[0] ) / 6.0;
802  }
803  else if ( ibcbeg == 2 )
804  {
805  b[0] = ybcbeg;
806  a[1+0*3] = 1.0;
807  a[0+1*3] = 0.0;
808  }
809  else
810  {
811  cout << "\n";
812  cout << "SPLINE_CUBIC_SET - Fatal error!\n";
813  cout << " IBCBEG must be 0, 1 or 2.\n";
814  cout << " The input value is " << ibcbeg << ".\n";
815  }
816 
817  // Set up the intermediate equations.
818  for ( i = 1; i < n-1; i++ )
819  {
820  b[i] = ( y[i+1] - y[i] ) / ( t[i+1] - t[i] )
821  - ( y[i] - y[i-1] ) / ( t[i] - t[i-1] );
822  a[2+(i-1)*3] = ( t[i] - t[i-1] ) / 6.0;
823  a[1+ i *3] = ( t[i+1] - t[i-1] ) / 3.0;
824  a[0+(i+1)*3] = ( t[i+1] - t[i] ) / 6.0;
825  }
826 
827  // Set up the last equation.
828  if ( ibcend == 0 )
829  {
830  b[n-1] = 0.0;
831  a[2+(n-2)*3] = -1.0;
832  a[1+(n-1)*3] = 1.0;
833  }
834  else if ( ibcend == 1 )
835  {
836  b[n-1] = ybcend - ( y[n-1] - y[n-2] ) / ( t[n-1] - t[n-2] );
837  a[2+(n-2)*3] = ( t[n-1] - t[n-2] ) / 6.0;
838  a[1+(n-1)*3] = ( t[n-1] - t[n-2] ) / 3.0;
839  }
840  else if ( ibcend == 2 )
841  {
842  b[n-1] = ybcend;
843  a[2+(n-2)*3] = 0.0;
844  a[1+(n-1)*3] = 1.0;
845  }
846  else
847  {
848  cout << "\n";
849  cout << "SPLINE_CUBIC_SET - Fatal error!\n";
850  cout << " IBCEND must be 0, 1 or 2.\n";
851  cout << " The input value is " << ibcend << ".\n";
852  }
853 
854  // Solve the linear system.
855  if ( n == 2 && ibcbeg == 0 && ibcend == 0 )
856  {
857  dvar_vector ret(0,1);
858  ret(0) = 0.0;
859  ret(1) = 0.0;
860  return ret;
861  }
862  else
863  {
864  dvar_vector ypp = d3_np_fs ( n, a, b );
865  dvar_vector ret(0,n-1);
866  if ( !ypp )
867  {
868  cout << "\n";
869  cout << "SPLINE_CUBIC_SET - Fatal error!\n";
870  cout << " The linear system could not be solved.\n";
871  }
872  ret = ypp;
873  return ret;
874  }
875 }
dvariable operator()(double u)
Description not yet available.
Definition: vspline.cpp:93
Base class for dvariable.
Definition: fvar.hpp:1315
dvar_vector & shift(int min)
Description not yet available.
Definition: fvar_arr.cpp:28
dvariable spline_cubic_val2(int n, const dvector &t, const prevariable &tval, const dvar_vector &y, const dvar_vector &ypp)
Evaluates a piecewise cubic spline at a point.
Definition: vspline.cpp:409
#define x
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
double splint(const dvector &xa, const dvector &ya, const dvector &y2a, double x)
Definition: cspline.cpp:92
ADMB variable vector.
Definition: fvar.hpp:2172
dvar_vector spline_cubic_set(int n, const dvector &t, const dvar_vector &y, int ibcbeg, dvariable ybcbeg, int ibcend, dvariable ybcend)
Computes the second derivatives of a piecewise cubic spline.
Definition: vspline.cpp:643
dvar_vector y2
Definition: fvar.hpp:5043
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
vcubic_spline_function(const dvector &_x, const dvar_vector &_y, double yp1=0.0, double ypn=0.0)
Description not yet available.
Definition: vspline.cpp:82
dvector spline(const dvector &x, const dvector &y, double yp1, double ypn)
Definition: cspline.cpp:37
static _THREAD gradient_structure * _instance
dvariable spline_cubic_val(int n, const dvector &t, double tval, const dvar_vector &y, const dvar_vector &ypp)
Evaluates a piecewise cubic spline at a point.
Definition: vspline.cpp:284
dvector & shift(int min)
Shift valid range of subscripts.
Definition: dvector.cpp:52
unsigned int size() const
Get number of elements in array.
Definition: dvector.h:209
int indexmin() const
Definition: fvar.hpp:2287
void allocate(int, int)
Allocate dvar_vector with indexmin = ncl and indexmax = nch.
Definition: fvar_arr.cpp:270
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
dvar_vector d3_np_fs(int n, const dvar_vector &_a, const dvar_vector &_b)
factors and solves a D3 system.
Definition: vspline.cpp:530
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
int indexmax() const
Definition: fvar.hpp:2292
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518