<!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><br><br><blockquote style="margin: 0 auto; padding: 0 2em; border-left:2px solid #00ADE5; white-space: pre-wrap ">Merci Phillip,Antoine,<br><br>Now I have something very close to what I am looking for<br><br>Thanks for your help<br><br>regards<br><br>Lloyd<br><br><br><br>------ Original Message ------<br>From: "P M" <p.muehlmann@gmail.com><br>To: "Users mailing list for Scilab" <users@lists.scilab.org><br>Sent: Monday, 10 Feb, 2020 At 9:46 AM<br>Subject: Re: [Scilab-users] ?==?utf-8?q? plotting a function that changes with x<br><br><div><div><div>Hi,<br></div><div>with the if-loop-approach you probably thought about this:<br></div><div><pre style="font-family: Monospaced;font-size: 12.0px;font-style: normal;"><span style="color: rgb(0,0,0);">x</span><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);">for</span> <span style="color: rgb(0,0,0);">i</span><span style="color: rgb(92,92,92);">=</span><span style="color: rgb(188,143,143);">1</span><span style="color: rgb(255,170,0);">:</span><span style="color: rgb(50,185,185);">length</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(0,0,0);">x</span><span style="color: rgb(74,85,219);">)</span><br/>    <span style="color: rgb(160,32,240);">if</span> <span style="color: rgb(74,85,219);">(</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(0,0,0);">x</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(0,0,0);">i</span><span style="color: rgb(74,85,219);">)</span><span style="color: rgb(92,92,92);"><</span><span style="color: rgb(188,143,143);">18</span><span style="color: rgb(74,85,219);">)</span> <span style="color: rgb(92,92,92);">==</span> <span style="color: rgb(218,112,214);">%T</span><span style="color: rgb(74,85,219);">)                   // elementwise comparison</span><br/>        <span style="color: rgb(160,32,240);">then</span> <span style="color: rgb(0,0,0);">y</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(0,0,0);">i</span><span style="color: rgb(74,85,219);">)</span> <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><span style="color: rgb(0,0,0);">x</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(0,0,0);">i</span><span style="color: rgb(74,85,219);">)</span><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/>        <span style="color: rgb(0,0,0);">y</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(0,0,0);">i</span><span style="color: rgb(74,85,219);">)</span><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><span style="color: rgb(0,0,0);">x</span><span style="color: rgb(74,85,219);">(</span><span style="color: rgb(0,0,0);">i</span><span style="color: rgb(74,85,219);">)</span><br/>    <span style="color: rgb(160,32,240);">end</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><span style="color: rgb(0,0,0);">x</span><span style="color: rgb(0,0,0);">,</span><span style="color: rgb(0,0,0);">y</span><span style="color: rgb(0,0,0);">,</span><span style="color: rgb(188,143,143);">2</span><span style="color: rgb(74,85,219);">)</span></pre>However it's a if-loop within a for loop...<br>Best regards,<br>Philipp</div></div></div><br><div class="gmail_quote"><div class="gmail_attr">Am So., 9. Feb. 2020 um 10:34 Uhr schrieb Antoine Monmayrant <<a href="mailto:amonmayr@laas.fr"><span class="wt_Email">amonmayr@laas.fr</span><span></span></a>>:<br></div><blockquote class="gmail_quote" style="margin: 0.0px 0.0px 0.0px 0.8ex;padding-left: 1.0ex;border-left-color: rgb(204,204,204);border-left-width: 1.0px;border-left-style: solid;">Hello,<br> <br> I think that (x>18) is not doing what you think it does.<br> See below two options to define  y piecewise.<br> Hope it helps,<br> <br> Antoine<br> <br> ----------------------<br> <br> //your code<br> clf<br>   x=(0:1:72)<br> // here you x<18 is not what your think (it's a boolean vector)<br> if x<18<br> then y = sin(x*%pi/24)<br> else<br>      y= 0.1*x<br> end<br> plot2d(x,y,2)<br> <br> // two options<br> <br> // using the fact that x>18 is converted into<br> // 1 when the condition is true<br> // 0 when the condition is false<br> y2 =  sin(x*%pi/24).*(x>18) + 0.1*x.*(x<=18);<br> <br> plot(x,y2,"ro");<br> <br> // using a range of indices & find<br> y3=0.1*x;<br> inds=find(x>18);<br> y3(inds)=sin(x(inds)*%pi/24);<br> <br> plot(x,y3,"g");<br> <br> ----------------------<br> <br> <br> <br> <br> Le Dimanche, Février 09, 2020 08:56 CET, Lloyd Judd <<a href="mailto:ltjudd@bigpond.com" target="_blank"><span class="wt_Email">ltjudd@bigpond.com</span><span></span></a>> a Ã©crit: <br> <br> > Hello, <br> > I am trying make a plot, the function of which changes depending on the <br> > value of x,. What I am really trying to do is to simulate solar panel <br> > out put where it roughly follows a sine  function during daylight but is <br> > basically zero from sunset to sunrise, and then later overlay that with <br> > the demand curve. But I am still experimenting with the code at this <br> > stage.<br> >  I tried all different ways;  using the "function" command and the "plot <br> > 2d" command . It only ever seems  to plot the last argument in the "if <br> > then else" statement.<br> > For example with this code;<br> > clf<br> >    x=(0:1:72)<br> >   if x<18<br> >       then y = sin(x*%pi/24)<br> >   else<br> >       y= 0.1*x<br> >    end<br> >   plot2d(x,y,2)it only plots  the y=0.1x partConversely if I put the <br> > sine function under the "else" statement, it only plots the  sin <br> > function.clfx=(0:1:72)<br> > if x<18 then<br> >      y=0.01*x<br> > else<br> >      y=sin(x*%pi/24)<br> > end<br> >   plot2d(x,y,2)What is the best way to plot a function that changes <br> > depending on the range of x?Thanks and regardsLloyd Judd<br> ><br> <br> _______________________________________________<br> users mailing list<br> <a href="mailto:users@lists.scilab.org" target="_blank"><span class="wt_Email">users@lists.scilab.org</span><span></span></a><br> <a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/mailman/listinfo/users</a><br> </blockquote></div> <hr>_______________________________________________<br><br/>users mailing list<br><br/><span class="wt_Email">users@lists.scilab.org</span><span></span><br><br/><a target="_blank" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a><br><br/></blockquote></body></html>