[Scilab-users] ?==?utf-8?q? plotting a function that changes with x
Lloyd Judd
ltjudd at bigpond.com
Mon Feb 10 16:28:07 CET 2020
Merci Phillip,Antoine,
Now I have something very close to what I am looking for
Thanks for your help
regards
Lloyd
------ Original Message ------
From: "P M" <p.muehlmann at gmail.com>
To: "Users mailing list for Scilab" <users at lists.scilab.org>
Sent: Monday, 10 Feb, 2020 At 9:46 AM
Subject: Re: [Scilab-users] ?==?utf-8?q? plotting a function that
changes with x
Hi,
with the if-loop-approach you probably thought about this:
x=(0:1:72)
for i=1:length(x)
if ((x(i)<18) == %T) // elementwise comparison
then y(i) = sin(x(i)*%pi/24)
else
y(i)= 0.1*x(i)
end
end
plot2d(x,y,2)However it's a if-loop within a for loop...
Best regards,
Philipp
Am So., 9. Feb. 2020 um 10:34 Uhr schrieb Antoine Monmayrant
<amonmayr at laas.fr <mailto:amonmayr at laas.fr> >:
Hello,
I think that (x>18) is not doing what you think it does.
See below two options to define y piecewise.
Hope it helps,
Antoine
----------------------
//your code
clf
x=(0:1:72)
// here you x<18 is not what your think (it's a boolean vector)
if x<18
then y = sin(x*%pi/24)
else
y= 0.1*x
end
plot2d(x,y,2)
// two options
// using the fact that x>18 is converted into
// 1 when the condition is true
// 0 when the condition is false
y2 = sin(x*%pi/24).*(x>18) + 0.1*x.*(x<=18);
plot(x,y2,"ro");
// using a range of indices & find
y3=0.1*x;
inds=find(x>18);
y3(inds)=sin(x(inds)*%pi/24);
plot(x,y3,"g");
----------------------
Le Dimanche, Février 09, 2020 08:56 CET, Lloyd Judd
<ltjudd at bigpond.com <mailto:ltjudd at bigpond.com> > a écrit:
> Hello,
> 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.
> 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.
> For example with this code;
> clf
> x=(0:1:72)
> if x<18
> then y = sin(x*%pi/24)
> else
> y= 0.1*x
> end
> plot2d(x,y,2)it only plots the y=0.1x partConversely if I put the
> sine function under the "else" statement, it only plots the sin
> function.clfx=(0:1:72)
> if x<18 then
> y=0.01*x
> else
> y=sin(x*%pi/24)
> end
> plot2d(x,y,2)What is the best way to plot a function that changes
> depending on the range of x?Thanks and regardsLloyd Judd
>
_______________________________________________
users mailing list
users at lists.scilab.org <mailto:users at lists.scilab.org>
http://lists.scilab.org/mailman/listinfo/users
<http://lists.scilab.org/mailman/listinfo/users>
_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
<http://lists.scilab.org/mailman/listinfo/users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20200211/48764985/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Capture truncated sine curve.JPG
Type: image/jpeg
Size: 121905 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20200211/48764985/attachment.jpe>
More information about the users
mailing list