kill(all)$

maxima :find local max,min,version 1.0
peter.vlasschaert@gmail.com, 20/11/2018

load packages :
=============

load(lrats)$
load(functs)$

How to use menu : discrete plot
===========================
list 1 : 3,4,5,6,7             =>  x values
list 2 :25,74,92,75,18   =>  y values

1e) data : given 'list' format 
----------------------------------------
list  => []
set => {}

a) number of data.
---------------------------

nu:5      ;

b) list 'data'.
------------------

list1:[3,4,5,6,7];
list2:[25,74,92,75,18];

length of list :
--------------------

nu1: length(list1);
nu2: length(list2);

c) discrete plot.
-----------------------
 Menu => Plot =>  Plot2d => push special : select  'discrete plot '
 x =   list1
 y =   list2
  expression :                                 'make  empty                  '
  ticks : 10
  variable : x  from 0  to 10           ' list1                                 '
  inline                                               ' plot inside work sheet'
  option : set grid

rem : removes in  the code extra :  [list1]  => list1
                                                                 [list2]  => list2

correction :  'see above'       =>  reason already list.
====================   

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

wxplot2d([['discrete, [list1], [list2]]], [x,0,10],
 [gnuplot_postamble, "set grid;"])$

  => wxplot2d([['discrete, list1, list2]], [x,0,10],
 [gnuplot_postamble, "set grid;"])$

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

plot 2d: ' discrete points '
=====================

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

wxplot2d([['discrete, list1, list2]], [x,0,10],
 [gnuplot_postamble, "set grid;"],[style,points],[point_type,diamond],[color,blue])$

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

rem :wxplot2d => plot2d , not inside document.

# local: max,min  , global: max,min

local    max : before min, after min
global max : max value in the range
local    min  : before max, after max
global min : min value in the range

## ) global

global : max,min   = >  list :  lmax,lmin
--------------------------------------------------------

gmax: lmax(list2);

gmin :lmin(list2);

max(25,74) = 74
-----------------------

p1:max(list2[1],list2[2]);

? for  , to get info  => 
==================

rmax : ?
------------

          for i:1 thru nu1-1  step 1 do (
if list2[i] < list2[i+1] then rmax:[max(list2[i],list2[i+1])])$

rmax;

position : rmax in  list2   =>  second element list rmax ?
----------------------------------------------------------------------------------

for i:1 thru nu1  step 1 do (
if rmax[1] = list2[i] then rmax:endcons(i,rmax))$

rmax;

coordinates :  global max  (plot)
===========================

coordmax:[list1[rmax[2]],list2[rmax[2]]];

rmin : ?
-----------

  for i:1 thru nu1-1  step 1 do (
if list2[i] > list2[i+1] then rmin:[min(list2[i],list2[i+1])])$

rmin;

position : rmin in  list2   =>  second element list rmin
------------------------------------------------------------------------------

for i:1 thru nu1  step 1 do (
if rmin[1] = list2[i] then rmin:endcons(i,rmin))$

rmin;

coordinates :  global min  (plot)
===========================

coordmax:[list1[rmin[2]],list2[rmin[2]]];

## ) local

rem :  'first entry,list2  ' , in the range can't be local 'max' or 'min'
=>       for loop will start at 'second entry,list2'
rem :  search for values in  'list2'

!  algo : local max   ' > if '
------------------------------------

empty list3 , to put in the local max
----------------------------------------------------

list3:[];

empty list4 , to put in the local max ,position
------------------------------------------------------------------

list4:[];

test 1: 
=====

for i:2 thru nu1-1 step 1 do (
if list2[i] > list2[i-1] and list2[i]> list2[i+1] then
   list3:endcons(list2[i],list3) ,
   list4:endcons(i,list4)  )$                              

list3;

mid position ,  92 , example , only 3 hold
------------------------------------------------------------
rem :  delete (a,[a,b,c,d])   =>  [b,c,d]
------------------------------------------------------------

list4;

'---------------------------------------------------------------------------------------------------'

list5 :  list localmaximum  =>  3e Column bb ,' with values'
list6 :  list localminimum   =>  4e Column bb , 'with values'
================================================

list5:makelist(0,i,1,nu1);
list6:makelist(0,i,1,nu1);

aa:matrix(list1,list2,list5,list6);

bb:transpose(aa);

rem :element matrix : bb[row][col]

local max,min : 3e column,4e column
===============================

local max :
---------------

for i:2 thru nu1-1 step 1  do (
 if bb[i][2] > bb[i-1][2]  and bb[i][2] > bb[i+1][2]  then
    bb[i][3] : bb[i][2]
 else
    bb[i][3] : 0 )$       

bb;

local max,min
---------------------

for i:2 thru nu1-1 step 1  do (
 if bb[i][2] < bb[i-1][2]  and bb[i][2] < bb[i+1][2]  then
    bb[i][4] : bb[i][2]
 else
    bb[i][4] : 0 )$   

bb;

use : make graphics , list7,list8
----------------------------------------------

list7:[];
list8:[];

for i:1 thru nu1 step 1 do(
 list7:endcons(bb[i][3],list7),
 list8:endcons(bb[i][4],list8)  
                                       )$

list7;
list8;

'-------------------------------------------------------------------------------------'

data :points , from  (list1[i],list2[i])   i=1....nu1,   nu1=nu2
-----------------------------------------------------------------------------------

wxplot2d([['discrete, list1, list2]], [x,0,10],
 [gnuplot_postamble, "set grid;"],[style,[points,5,5,3]])$

x :values ,  'list1'
y :values ,  'list2'

p1:list1;
p2:list2;

local maximum: y different from ' y=0 '
--------------------------------------------------------

wxplot2d([['discrete, list1, list7]], [x,0,10],[color,red],
 [gnuplot_postamble, "set grid;"],[style,[points,5,5,3]])$

wxplot2d([['discrete, list1, list2],['discrete, list1, list7]], [x,0,10],[color,red],
 [gnuplot_postamble, "set grid;"],[style,[points,5,5,3]])$

local max: 'info',list7.

wxplot2d([['discrete, list1, list2],['discrete, list1, list7]], [x,0,10],[color,red,blue],
 [gnuplot_postamble, "set grid;"],[style,points,points],[point_type,diamond,asterisk])$

 ;

rem : point : (5,92)  local maximum also in this example a global max.

local min: 'info' ,list8.

wxplot2d([['discrete, list1, list2],['discrete, list1, list8]], [x,0,10],[color,red,black],
 [gnuplot_postamble, "set grid;"],[style,points,points],[point_type,diamond,asterisk])$

rem :  no local minimum in this interval.