comparison liboctave/CMatrix.cc @ 9653:e087d7c77ff9

improve linspace in liboctave
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 18 Sep 2009 15:27:09 +0200
parents a9b37bae1802
children 3429c956de6f
comparison
equal deleted inserted replaced
9652:ecdb275bd41b 9653:e087d7c77ff9
4064 } 4064 }
4065 4065
4066 return result; 4066 return result;
4067 } 4067 }
4068 4068
4069 ComplexMatrix linspace (const ComplexColumnVector& x1,
4070 const ComplexColumnVector& x2,
4071 octave_idx_type n)
4072
4073 {
4074 if (n < 1) n = 1;
4075
4076 octave_idx_type m = x1.length ();
4077
4078 if (x2.length () != m)
4079 (*current_liboctave_error_handler) ("linspace: vectors must be of equal length");
4080
4081 NoAlias<ComplexMatrix> retval;
4082
4083 retval.clear (m, n);
4084 for (octave_idx_type i = 0; i < m; i++)
4085 retval(i, 0) = x1(i);
4086
4087 // The last column is not needed while using delta.
4088 Complex *delta = &retval(0, 1);
4089 for (octave_idx_type i = 0; i < m; i++)
4090 delta[i] = (x2(i) - x1(i)) / (n - 1.0);
4091
4092 for (octave_idx_type j = 1; j < n-1; j++)
4093 for (octave_idx_type i = 0; i < m; i++)
4094 retval(i, j) = retval(i, j-1) + delta[i];
4095
4096 for (octave_idx_type i = 0; i < m; i++)
4097 retval(i, n-1) = x2(i);
4098
4099 return retval;
4100 }
4101
4069 MS_CMP_OPS (ComplexMatrix, Complex) 4102 MS_CMP_OPS (ComplexMatrix, Complex)
4070 MS_BOOL_OPS (ComplexMatrix, Complex) 4103 MS_BOOL_OPS (ComplexMatrix, Complex)
4071 4104
4072 SM_CMP_OPS (Complex, ComplexMatrix) 4105 SM_CMP_OPS (Complex, ComplexMatrix)
4073 SM_BOOL_OPS (Complex, ComplexMatrix) 4106 SM_BOOL_OPS (Complex, ComplexMatrix)