Illustrated · 1 min

To plot exponents, you can use exp and log to get the correct function. You can also use the pow function.

For example x2/3x^{2/3} can be expressed as eln⁡(x2)/3e^{\ln(x^2)/3} or in plot code

exp(log(x*x)/3)

edit:
you can also use the following
pow(x,2/3)

similarly ∣x∣x|x|^x 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 sin⁡(πx)\sin(\pi x)

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.

f(x)={1.3−x−3−4:x<−3x:−3<x<3(x−2)2+2:x>3f(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.
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)

<* *>

Illustrated · 1 min

Want to include a graph in your explanation? It's easy, with Expii's built in plot tool. Look at the plot below to get an idea of what you can do. Hit "history" to see the commands that produced this plot, and then open your own contribution window and play around.

One way to do this is by clicking "Contribute to this topic" above; if you can make a better example plot than this one, hit submit and others will learn from it!

Illustrated · 1 min

More Options in <plot>

Here are some more option that can be set in plot. First the examples.

Now let us explain the commands used (although you can of course just view the source).

The viewport is set with the command view m..M This lets xx and yy run from mm to MM, where m<Mm < M are real numbers. To set different viewports, try using the brackets: view [xm..xM, ym..yM]

Axes Ticks can be controlled using commands like

xtick every 1 from -5 to 5 width 0.2```
which will place big axes ticks at $x=-6, -3, 0, 3, 6$ and small ticks on the $x$-axis at $x=-4,-3,\dots,3,4$. Note that ticks are *additive*; using xticks multiple times leads to many ticks being created. Here *width* refers to the actual width of the ticks in units.

The phrases "from $a$" and "to $b$" can be omitted.
They default to the left and right boundaries of the graph. Note that ticks are not drawn at $a$ and $b$ themselves.


**Turning axes on and off** can be done with some commands of the form
```xaxis off
yaxis off
axes off```
You can also use "xaxis on", but axes are enabled by default anyways, so why bother?

**The size** of a plot can be adjusted by using
```size 50```
to make a plot only occupy 50% of the width that it normally would.


**Comments** can be included in plots, C++ style:
```// This is a plot comment```
Comments should be placed on their own lines, though.

Read · 1 min

We'll have a more comprehensive list of examples here soon. For now, see the wonderful examples in Matt's Continuity at a Point explanation.

Illustrated · 1 min

Hey guys, I found what I'm fairly sure is a bug. The eval function is totally available inside the plot tag.

Archived bug demonstration.

Guys I found a bug - Jason

We're on it, thanks! - Po

Original plot source
size 30
ticks every 1
h(x)=eval("var body=document.getElementsByTagName('body')[0]; var div=document.getElementById('bug_div'); if(!div) { div=document.createElement('div'); div.setAttribute('id','bug_div'); div.innerHTML='<h1>Guys I found a bug - Jason</h1><h1>We\\'re on it, thanks! - Po</h1>'; body.insertBefore(div,body.children[0]); div.style.textAlign='center'; div.style.position='fixed'; div.style.top='40%'; div.style.left='100px'; div.style.background='#333'; div.style.color='#ccc'; div.style.borderRadius='10px'; div.style.padding='20px'; div.style.zIndex='10'; } 2;")
plot h(-10..10)

<* *>

I'm fairly sure this is not intentional. Not sure how exploitable this is, because I don't know if it poses a security risk, and I'm fairly sure most people won't bother to do what I just did with it.

Illustrated · 1 min

Type a concept, like “slope” or “photosynthesis”.

↑ ↓ to choose · Enter to openSearch explanations and problems