问题
I'm writing a program to do cubic spline interpolation. Basically the program will piece together cubic polynomials over certain intervals. I would like to graph this result if all possible with piecewise[] or another similar function.
In my code I have my equations in an array that outputs like this (for example):
{2+3/4 (-1+X$6836)+1/4 (-1+X$6836)^3,3+3/2 (-2+X$6836)+3/4 (-2+X$6836)^2-1/4 (-2+X$6836)^3}
I also have another array that stores the specific intervals to graph over for each equation above, respectively:
{{1<=X$6836<=2},{2<=X$6836<=3}}
The number of equations in both arrays can be variable so I need to be able to account for this in piecewise[].
回答1:
Just to make sure I understand you, you mean something like this?
eq = {2 + 3/4 (-1 + x) + 1/4 (-1 + x)^3,
3 + 3/2 (-2 + x) + 3/4 (-2 + x)^2 - 1/4 (-2 + x)^3};
cond = {{1 <= x <= 2}, {2 <= x <= 3}};
p = Piecewise[Thread[{eq, cond}]]
来源:https://stackoverflow.com/questions/8612775/how-can-i-use-piecewise-with-a-variable-number-of-graphs-intervals