matlab,interpolation,handle,curve-fitting,piecewise

It's not all clear but why not to puts things into a class ? classdef Piecewise < handle methods % Construction function [this] = Piecewise(xmeas, ymeas) ... here compute xTrans and coeffMat... end % Interpolation function [yinterp] = Evaluate(xinterp) ... Here use previously computed xTrans and coeffMat ... end end...

python,numpy,scipy,curve-fitting,piecewise

You could use masked regions for piece-wise functions: def two_lines(x, a, b, c, d): out = np.empty_like(x) mask = x < 10 out[mask] = a*x[mask] + b out[~mask] = c*x[~mask] + d return out First test with two different positive slopes: x = np.array([0, 1, 2, 3, 4, 5, 6,...

matlab,plot,spline,piecewise,cubic

That's pretty easy. You've already done half of the work by defining an anonymous function that is for the cubic spline in between each interval. However, you need to make sure that the operations in the function are element-wise. You currently have it operating on scalars, or assuming that we...

You are using predict.segemented incorrectly. Like nearly all the predict() functions, your newdata parameter should be a data.frame, not a vector. Also, it needs to have names that match the variables used in your regression. Try predict.segmented(seg_model, data.frame(x=xtest)) instead. When using a function for the first time, be sure the...

There are two places where you need to use the . operator: you perform a division too: n = -10:10 k(n>0) = (1/6) .^ n(n>0) ./ n(n>0); k(n==0) = log(32); k(n<0) = (1/4) .^ -n(n<0) ./ n(n<0); ...

function,integer,arguments,piecewise

This function runs correctly. def Li(x): return piecewise(float(x), [x < 0, x >= 0], [lambda t: sin(t), lambda t: cos(t)])...

matlab,spline,piecewise,cubic-spline

This is probably the easiest way to get pp1 + pp2 Adding to the code in the question: pp12 = @(x) ppval(pp1,x)+ppval(pp2,x); breaks = unique([pp1.breaks,pp2.breaks]); pp3 = spline(breaks,pp12(breaks)); plot(tnew,ppval(pp3,tnew),'k:'); Gives the dotted black line: with pp3 being in piecewise-polynomial form with segments defined only by the breakpoints of pp1 and...

In gnuplot you can split a line in several parts either when you have an invalid data value somewhere, or an empty line. For the first situation, you could check inside the using statement, if the difference to the previous point is too large, and invalidate the current point. But...

Will scipy's 1d interpolation functions work? import numpy as np from scipy.interpolate import interp1d x = y = np.arange(5) f = interp1d(x,y, kind="linear", fill_value=0., bounds_error=False) print f(0) print f(2) print f(3) print f(3.4) Which gives: 1.0 2.0 3.0 3.4 ...