# [LON-CAPA-users] Piecewise Linear Functions

Harding, Gene L glhardin at purdue.edu
Sat Mar 21 22:38:14 EDT 2020

```Thanks Justin! (Sorry for the slow reply; stuck in the lab for a few hours this afternoon/evening.)

Gene L. Harding, PE
Associate Professor of ECET
Purdue University
574-520-4190
https://polytechnic.purdue.edu/south-bend/

From: LON-CAPA-users <lon-capa-users-bounces at mail.lon-capa.org> On Behalf Of Justin Gray
Sent: Saturday, March 21, 2020 3:34 PM
To: Discussion list for LON-CAPA users <lon-capa-users at mail.lon-capa.org>
Subject: Re: [LON-CAPA-users] Piecewise Linear Functions

Hi Gene,

To answer your first question, here is a sample piecewise-defined function in Gnuplots:

<gnuplot width="400" solid="0" plotcolor="monochrome" gridlayer="off" bmargin="default" font="9" alttag="dynamically generated plot" bgcolor="xffffff" texfont="22" transparent="off" plottype="Cartesian" rmargin="default" gridtype="Cartesian" minor_ticscale="0.5" fontface="sans-serif" grid="on" align="middle" texwidth="93" height="300" border="on" samples="1000" fgcolor="x000000" major_ticscale="1" tmargin="default" lmargin="default" fillstyle="empty">
<axis yzero="off" xformat="on" xmin="-10.0" yformat="on" color="x000000" ymax="10.0" ymin="-10.0" xmax="10.0" xzero="off" />
<curve
linestyle="lines"
color="x000000"
pointtype="1"
linetype="solid"
linewidth="1"
name=""
limit="closed"
pointsize="1" >
<function>x < 0 ? -x : x**2</function>
</curve>
</gnuplot>

Best,
Justin

--

Justin Gray
Senior Lecturer | Department of Mathematics
Simon Fraser University | SCK 10531
8888 University Dr., Burnaby, B.C. V5A 1S6
T: 778.782.4237

Simon Fraser University is located on the Unceded Coast Salish Territories of the xʷməθkʷəy̓əm (Musqueam), Səl̓ílwətaʔ/Selilwitulh (Tsleil-Waututh), Kwikwitlem, and Skwxwú7mesh Úxwumixw (Squamish) Peoples

On Sat, Mar 21, 2020 at 11:36 AM Harding, Gene L <glhardin at purdue.edu<mailto:glhardin at purdue.edu>> wrote:
Hi,

Does anyone know how to define a piecewise linear function in LON-CAPA, and plot it with gnuplot? And, a related question: How  do you put plots next to each other?

I need to display a plot of voltage on one graph, with a plot of phase-angle-fired half-sine current right below it on a separate graph, but using the same horizontal axis values and scale. The multiplot command in gnuplot allows multiple plots next to each other, similar to MATLAB, and the ternary operator allows definition of piecewise linear functions, but I don’t know how to implement either of them from within LON-CAPA.

Best regards,

Gene L. Harding, PE
Associate Professor of ECET
Purdue University
574-520-4190
https://polytechnic.purdue.edu/south-bend/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20200322/17f8a443/attachment.html>
```