kill(all)$

maxima : piecewise integration & piecewise plot (2D),version 1.0
peter.vlasschaert@gmail.com,06/06/2022

use : defint ,integrate. ' see below'.
use :unit_step(x)
use : if construction (→ piecewise )

→ function : piecewise interval 

p1:[2*x,x^2,5*x-4,x^2-4];

→ values : piecewise interval

p1a:[0,2,8,15,20];

relation between two lists : {p1,p1a}
-----------------------------------------------

0 → 2  :2*x
2 → 8  : x^2
8 →15  :5*x-4
15 →20 :x^2-4

integration : piecewise functions
-------------------------------------------

→ without : sum

p2a:defint(p1[1],x,p1a[1],p1a[2]);
p2b:defint(p1[2],x,p1a[2],p1a[3]);
p2c:defint(p1[3],x,p1a[3],p1a[4]);
p2d:defint(p1[4],x,p1a[4],p1a[5]);

s1:p2a+p2b+p2c+p2d;

→ with :sum

s2:sum(ev(defint(p1[i],x,p1a[i],p1a[i+1]),nouns),i,1,length(p1));

check :

is(s1=s2);

s2a:sum(ev(integrate(p1[i],x,p1a[i],p1a[i+1]),nouns),i,1,length(p1));

general : integration two maxima ' commands': integrate , defint

is(s2=s2a);

→ fig : 1

wxplot2d([unit_step(x)*2*x], [x,0,3])$

→ use: unit_step 

s3:sum(p1[i]*unit_step(x-p1a[i]),i,1,4);

s3a:makelist(p1[i]*unit_step(x-p1a[i]),i,1,4);

superposition of functions = som functions:

→ fig 2:

wxplot2d([s3], [x,0,20])$

separated functions of the lisr:
---------------------------------------

s4:makelist(p1[i]*unit_step(x-p1a[i]),i,1,4);

→ fig:3

wxplot2d(s4, [x,0,20])$

piecewise function  :  plot "f(x)"
=======================
f(x)=
-2/3*x-4  if x≤ -6
-4            if -6<x≤ 3
2*x-3       if x > 3

ref :https://www.youtube.com/watch?v=aljWAlAKT3w

f(x):=if x≤ -6 then -2/3*x+4 
         else if x > -6 and x ≤ 3 then -4
         else if x>3 then 2*x-3;

f(-2);

→ fig: 4

wxplot2d([f(x)], [x,-10,10])$

example : maxima on youtube.

ref :https://www.youtube.com/watch?v=0s64paanq9Y

f1(x) =
x+6           if x≤ -2
x^2           if x≤ 1
1/x            if x> 1

f1(x):=if x≤ -2 then x+6
         else if x≤ 1 then x^2
         else if x>1 then 1/x;

→ fig:4a

wxplot2d([f1(x)], [x,-5,5])$

same video : youtube.

f2(x):=if x≤ -2 then x+6
         else if x≤ 1 then x^2
         else 1/x;

→ fig: 4b

wxplot2d([f2(x)], [x,-5,5])$

rem : fig 4a = fig 4b .

example 3: f3(x)
-----------------------
→ [2*x,x^2,5*x-4,x^2-4]
→ [0,2,8,15,20]
f3(x) =
2*x           if x≥0 and  x≤ 2
x^2           if x> 2 and x ≤ 8
5*x-4         if x>8  and x ≤ 15
x^2-4         if x >15 and x ≤ 20

relation : "piecewise plot & integration". see above.

f3(x):=if x≥0 and  x≤ 2 then 2*x
            else if x> 2   and x ≤ 8   then x^2
            else if x> 8   and x ≤ 15 then 5*x-4
            else if x> 15 and x ≤ 20 then x^2-4;

→ fig:5

wxplot2d([f3(x)], [x,0,20])$

f3(5);

→p1a:[0,2,8,15,20]

makelist(f3(x),x,p1a);

see relation between : fig:5 & fig:3

-----------------------------------------------------------------------------------------------------------------------------------