My solution to this kind of problem has been to use Heaviside
functions such as the following example.
However, in this example, the plot produces a vertical line at the
discontinuity. Is there a simple way to avoid this?
UnitStep(x) := (signum(x) + 1)/2;
f(t):= (1 - UnitStep(t-2))*(t-3) + UnitStep(t-2)*t^2;
plot(f(t),[t,-1,5]);
-sen
On Fri, 17 Nov 2006, Robert Dodier wrote:
> On 11/17/06, Andrej Vodopivec <andrej.vodopivec at gmail.com> wrote:
>
>> (%i1) f(x) := if x<=2 then x-3 else x^2;
>> (%o1) f(x):=if x<=2 then x-3 else x^2
>> (%i2) plot2d([[parametric,t,'(f(t)),[t,-1,2]],[parametric,t,'(f(t)),[t,2
>> +0.000001,5]]],[x,-1,5]);
>>
>> The difference is the you quote f(t) in plot2d.
>
> Agreed with Andrej here -- a couple of other solutions.
>
> (1) Just put the name of the function in the plot expression
> (i.e. don't indicate the argument). E.g.
>
> f(x) := if x<=2 then x-3 else x^2;
> plot2d ([[parametric, t, f, [t, -1, 2]], [parametric, t, f, [t, 2 +
> 0.000001, 5]]], [x, -1, 5]);
>
> (2) Maxima 5.10.0 comes with an add-on package boolsimp which
> implements unevaluated conditionals. This makes working with
> functions defined piecewise more natural. E.g.
>
> load (boolsimp);
> f(x) := if x<=2 then x-3 else x^2;
> plot2d ([[parametric, t, f(t), [t, -1, 2]], [parametric, t, f(t), [t,
> 2 + 0.000001, 5]]], [x, -1, 5]);
>
> so your original plot2d expression works.
>
> HTH
> Robert Dodier
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
--
---------------------------------------------------------------------------
| Sheldon E. Newhouse | e-mail: sen1 at math.msu.edu |
| Mathematics Department | |
| Michigan State University | telephone: 517-355-9684 |
| E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562 |
---------------------------------------------------------------------------