How can I use Piecewise[] with a variable number of graphs/intervals

瘦欲@ 提交于 2019-12-14 03:53:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!