如何将 Piecewise[] 与可变数量的图形/间隔一起使用 [英] How can I use Piecewise[] with a variable number of graphs/intervals

查看:28
本文介绍了如何将 Piecewise[] 与可变数量的图形/间隔一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序来进行三次样条插值.基本上,该程序将在某些间隔内拼凑三次多项式.如果可能的话,我想用piecewise[] 或其他类似函数绘制这个结果.

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

推荐答案

为了确保我理解你,你的意思是这样的?

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

这篇关于如何将 Piecewise[] 与可变数量的图形/间隔一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆