<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body>Hello, <div>I am trying make a plot, the function of which changes depending on the value of x,. What I am really trying to do is to simulate solar panel out put where it roughly follows a sine  function during daylight but is basically zero from sunset to sunrise, and then later overlay that with the demand curve. But I am still experimenting with the code at this stage.<div> I tried all different ways;  using the "function" command and the "plot 2d" command . It only ever seems  to plot the last argument in the "if then else" statement.</div><div>For example with this code;</div><div><pre style="font-family: Monospaced;font-size: 12.0px;"><span style="color: rgb(174,92,176);">clf</span><br>  x<span style="color: rgb(92,92,92);">=</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(188,143,143);">0</span><span style="color: rgb(255,170,0);">:</span><span style="color: rgb(188,143,143);">1</span><span style="color: rgb(255,170,0);">:</span><span style="color: rgb(188,143,143);">72</span><span style="color: rgb(74,85,219);">)</span><br> <span style="color: rgb(160,32,240);">if</span> x<span style="color: rgb(92,92,92);"><</span><span style="color: rgb(188,143,143);">18</span><br>     <span style="color: rgb(160,32,240);">then</span> y <span style="color: rgb(92,92,92);">=</span> <span style="color: rgb(50,185,185);">sin</span><span style="color: rgb(74,85,219);">(</span>x<span style="color: rgb(92,92,92);">*</span><span style="color: rgb(218,112,214);">%pi</span><span style="color: rgb(92,92,92);">/</span><span style="color: rgb(188,143,143);">24</span><span style="color: rgb(74,85,219);">)</span><br> <span style="color: rgb(160,32,240);">else</span><br>     y<span style="color: rgb(92,92,92);">=</span> <span style="color: rgb(188,143,143);">0.1</span><span style="color: rgb(92,92,92);">*</span>x<br>  <span style="color: rgb(160,32,240);">end</span><br> <span style="color: rgb(50,185,185);">plot2d</span><span style="color: rgb(74,85,219);">(</span>x,y,<span style="color: rgb(188,143,143);">2</span><span style="color: rgb(74,85,219);">)</span></pre><pre style="font-size: 12px;"><font face="times new roman, serif" style="">it only plots  the y=0.1x part</font></pre><pre style=""><font face="times new roman, serif" style=""><span style="font-size: 12px;">Conversely if I put the sine function under the "else" statement, it only plots the  sin function.</span></font></pre><pre style="font-size: 12px;"><span style="color: rgb(174, 92, 176); text-decoration-line: underline; font-family: Monospaced;">clf</span></pre><pre style=""><pre style="font-size: 12px; font-family: Monospaced;">x<span style="color: rgb(92, 92, 92);">=</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">0</span><span style="color: rgb(255, 170, 0);">:</span><span style="color: rgb(188, 143, 143);">1</span><span style="color: rgb(255, 170, 0);">:</span><span style="color: rgb(188, 143, 143);">72</span><span style="color: rgb(74, 85, 219);">)</span><br/><span style="color: rgb(160, 32, 240);">if</span> x<span style="color: rgb(92, 92, 92);"><</span><span style="color: rgb(188, 143, 143);">18</span> <span style="color: rgb(160, 32, 240);">then</span><br/>    y<span style="color: rgb(92, 92, 92);">=</span><span style="color: rgb(188, 143, 143);">0.01</span><span style="color: rgb(92, 92, 92);">*</span>x<br/><span style="color: rgb(160, 32, 240);">else</span> <br/>    y<span style="color: rgb(92, 92, 92);">=</span><span style="color: rgb(50, 185, 185);">sin</span><span style="color: rgb(74, 85, 219);">(</span>x<span style="color: rgb(92, 92, 92);">*</span><span style="color: rgb(218, 112, 214);">%pi</span><span style="color: rgb(92, 92, 92);">/</span><span style="color: rgb(188, 143, 143);">24</span><span style="color: rgb(74, 85, 219);">)</span><br/><span style="color: rgb(160, 32, 240);">end</span><br/> <span style="color: rgb(50, 185, 185);">plot2d</span><span style="color: rgb(74, 85, 219);">(</span>x,y,<span style="color: rgb(188, 143, 143);">2</span><span style="color: rgb(74, 85, 219);">)</span></pre><pre style=""><font face="times new roman, serif"><span style="font-size: 12px;">What is the best way to plot a function that changes depending on the range of x?</span></font></pre><pre style="font-size: 12px;"><span style="font-family: "times new roman", serif;">Thanks</span><span style="font-family: "times new roman", serif;"> and regards</span></pre><pre style="font-size: 12px;"><font face="times new roman, serif" style="">Lloyd Judd</font></pre></pre></div> </div></body></html>