Illustrated · 1 min
To plot exponents, you can use exp and log to get the correct function. You can also use the pow function.
using exp and log
For example can be expressed as or in plot code
exp(log(x*x)/3)
edit:
you can also use the following
pow(x,2/3)
similarly can be written
exp(x*log(abs(x)))
edit:
this can also be written as:
pow(abs(x),x)
Since I'm not sure if there is documentation for the available functions or where they are, I will post a list here for reference. They form a subset of the javascript Math library. see here
Functions:
abs(x)
sin(x)
cos(x)
tan(x)
asin(x)
acos(x)
atan(x)
sqrt(x)
pow(n,m) - e.g. x^3 is pow(x,3), and 2^x is pow(2,x). Roughly equivalent to exp(m*log(n)).
exp(x)
log(x)
floor(x)
ceil(x)
round(x)
max(x1,x2,x3,...)
min(x1,x2,x3,...)
< - returns 1 if true, 0 otherwise
> - returns 1 if true, 0 otherwise
== - returns 1 if true, 0 otherwise // don't use
!= - returns 1 if true, 0 otherwise // don't use
&& - returns 0 or second arg
|| - returns 0 or first arg
! - prefix, returns 1 if arg is 0, 0 otherwise
((pred && ""+true_val) || (false_val)) - if pred then true_val else false_val. // the "" prevent false_val from being returned if true_val==0 returns a string. Functions that return strings containing number values will convert the string back to a number.
random()
Constants: I haven't figured out how to get constants, nor how to define constants, so here's what I've done.
p1(x)=acos(-1)*x // This is pi*x, you can't define pi(x). So I chose "p1", because it looks like "pi".
e(x)=exp(1) // This is e as a constant function. #kindastupid
Now we plot
To get piecewise functions we hack a little.
define the following (you can copy and paste):
test(x)=(x/(abs(x))+1)/2 // or better yet
test(x)=ceil((x/(abs(x)+0.00001))) // use this, or even simpler just use x>0
not(x)=-x+1 // not can look nicer, but you can also just use '!'
test(x-y) // 1 if x>y 0 otherwise // just use (x-y)>0
not(test(y-x)) // 1 if x>=y 0 otherwise
These are nearly identical functions written using various idioms, shifted for visibility.
Original plot source
ticks every 1 width 0.2
test(x)=ceil((x/(abs(x)+0.00001)))
not(x)=-x+1
f1(x)=pow(1.3,-x-3)-4
f2(x)=x
f3(x)=pow(x-2,2)+2
g(x) = f1(x)*test(-3-x)+f2(x)*test(x+3)*test(3-x)+test(x-3)*f3(x) + 1
h(x) = ((((x<-3) && ""+(pow(1.3,-x-3)-4)) || ((x<3) && ""+x) || (pow(x-2,2)+2))) // can't shift this inside the function since it becomes a string... the function makes it a number again
f(x) = (x<-3)*f1(x) + not(x<-3)*((x<3)*f2(x) + not(x<3)*f3(x)) + 2
// i(x) = eval("(x< -3) ? f1(x) : ((x<3) ? f2(x) : f3(x))") - 1
plot f(-10..10) blue
plot g(-10..10) green
plot h(-10..10) orange
//plot i(-10..10) red
label [-7,7] These are nearly identical functions written using various idioms, shifted for visibility.
label [1,5] \[f(x)=\left\{\begin{array}{ll} 1.3^{-x-3}-4 & : x <-3 \\ x & : -3 < x <3\\ (x-2)^2+2 & : x>3 \end{array}\right.\]Here's another plot:
<*Test plots below
Parametric
Original plot source
y1(t)=6*cos(t)
y2(t)=6*sin(t)
y(t)=eval("[6*Math.cos(t),6*Math.sin(t)]")
plot [y1,y2](0..6.3)Sierpinski
Experimental plot, with fixed randomness for a repeatable illustration.
Original plot source
view [-0.5..1.5,-0.3..1]
c(x)=sqrt(3)/2*x
a(x)=eval("[[1,0],[0,0],[0.5,c(1)]][Math.floor(3*Math.random())]")
b(x)=eval("function closure(){if(typeof closure.pos =='undefined') {var r=Math.random(); closure.pos=[0.5*r+(1-r)*Math.random(),c(r)]; } var k = a(0); closure.pos[0]+=k[0]; closure.pos[0]/=2; closure.pos[1]+=k[1]; closure.pos[1]/=2; return closure.pos; } return closure;")
h(x)=eval("if((typeof h.count =='undefined')){ h.count=0; h.f=b(0); h.val=h.f(); } if(x<0){ h.count=0;} var ans = 0; if(x>=0) {ans = h.val[h.count++]; h.count%=2; if(!h.count) h.val=h.f(); } console.log(ans); ans;")
mark [h @ -1]
mark [h @ 0]
mark [h @ 0]
mark [h @ 0]
//mark [h,h](0)<* *>