Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/QLNet/Math/Interpolations/MixedInterpolation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public MixedInterpolationImpl(List<double> xBegin, int xEnd,
xBegin2_ = xBegin.GetRange(n_, xBegin.Count - n_);
yBegin2_ = yBegin.GetRange(n_, yBegin.Count - n_);

Utils.QL_REQUIRE(xBegin2_.Count < size_, () => "too large n (" + n + ") for " + size_ + "-element x sequence");
Utils.QL_REQUIRE(xBegin2_.Count < xBegin.Count, () => "too large n (" + n + ") for " + size_ + "-element x sequence");

Comment on lines 56 to 60
switch (behavior)
{
Expand All @@ -65,8 +65,16 @@ public MixedInterpolationImpl(List<double> xBegin, int xEnd,
interpolation2_ = factory2.interpolate(xBegin_, size_, yBegin_);
break;
case Behavior.SplitRanges:
interpolation1_ = factory1.interpolate(xBegin_, n_, yBegin_);
interpolation2_ = factory2.interpolate(xBegin2_, size_ - n, yBegin2_);
if (size_ <= n_)
{
interpolation1_ = factory1.interpolate(xBegin_, size_, yBegin_);
interpolation2_ = interpolation1_;
}
Comment on lines +68 to +72
Comment on lines +68 to +72
else
{
interpolation1_ = factory1.interpolate(xBegin_, n_, yBegin_);
interpolation2_ = factory2.interpolate(xBegin2_, size_- n_, yBegin2_);
}
break;
default:
Utils.QL_FAIL("unknown mixed-interpolation behavior: " + behavior);
Expand All @@ -83,14 +91,14 @@ public override void update()

public override double value(double x)
{
if (x<(xBegin2_.First()))
if (xBegin2_.Count == 0 || x < (xBegin2_.First()))
return interpolation1_.value(x, true);
return interpolation2_.value(x, true);
Comment on lines 92 to 96
}
Comment on lines 92 to 97

public override double primitive(double x)
{
if (x<(xBegin2_.First()))
if (xBegin2_.Count == 0 || x < (xBegin2_.First()))
return interpolation1_.primitive(x, true);
return interpolation2_.primitive(x, true) -
interpolation2_.primitive(xBegin2_.First(), true) +
Expand All @@ -99,14 +107,14 @@ public override double primitive(double x)

public override double derivative(double x)
{
if (x < (xBegin2_.First()))
if (xBegin2_.Count == 0 || x < (xBegin2_.First()))
return interpolation1_.derivative(x, true);
return interpolation2_.derivative(x, true);
}

public override double secondDerivative(double x)
{
if (x < (xBegin2_.First()))
if (xBegin2_.Count == 0 || x < (xBegin2_.First()))
return interpolation1_.secondDerivative(x, true);
return interpolation2_.secondDerivative(x, true);
}
Expand Down