2

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[].

bobbymcr
  • 23,769
  • 3
  • 56
  • 67
mwc33
  • 43
  • 1
  • 4

1 Answers1

3

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}]]

enter image description here

Nasser
  • 12,849
  • 6
  • 52
  • 104
  • correct. Sorry about all the extraneous ($6836) numbers. I wasn't sure how to get rid of them. – mwc33 Dec 23 '11 at 08:21
  • @mwc33 in the future, a simple use of `ReplaceAll`, shorthand form `/.` will help with that. Try: `{your expression list} /. X$6836 -> x` – Mr.Wizard Dec 23 '11 at 20:32