function continuityexamplesMain(){this.version='1.05';w=570;h=510;graphLt=0;graphTp=0;graphWd=550;graphHt=340;coords=new Coords(graphLt,graphTp,graphWd,graphHt,-5,-3,5,3,true);canvasWd=graphWd;canvasHt=graphHt;clrs=["darkblue","orange"];examples=[["sin(x)","Continuous",[]],["x2","Continuous",[]],["1/(x-1)","Not continuous: vertical asymptote at x=1",[1]],["(x2-1)/(x-1)","Not continuous: hole at x=1",[1]],["sign(x-1.5)","Not continuous: jump at x=1.5",[1.5]]];gaps=[];var s='';s+='
';s+='
';for(i=0,len=examples.length;i'+ex[0]+'';} s+='
';s+='
sin(x)
';s+='
';s+='
Zoom:
';s+='';s+='';s+='';s+='
© 2015 MathsIsFun.com v'+this.version+'
';s+='
';document.write(s);el=document.getElementById('canvasId');ratio=3;el.width=canvasWd*ratio;el.height=canvasHt*ratio;el.style.width=canvasWd+"px";el.style.height=canvasHt+"px";g=el.getContext("2d");g.setTransform(ratio,0,0,ratio,0,0);g.translate(0.5,0.5);currZoom=1;aVal=1;parser=new Parser();dragging=false;downX=0;downY=0;prevX=0;prevY=0;el.addEventListener("mousedown",mouseDownListener,false);window.addEventListener("mousemove",mouseMoveListener,false);window.addEventListener("mouseup",mouseUpListener,false);el.addEventListener('touchstart',ontouchstart,false);window.addEventListener('touchmove',ontouchmove,false);window.addEventListener('touchend',ontouchend,false);doExample(0);doGraph();} function linkPop(){var pop=document.getElementById('linkpop');pop.style.transitionDuration="0.3s";pop.style.opacity=1;pop.style.zIndex=12;pop.style.left='100px';document.getElementById('linkbox').value=makeURL();} function makeURL(){var s="../data/function-grapherd41d.html?";var f0=document.getElementById('f0').value;if(f0.length>0){s+="func1="+encodeURIComponent(f0)+"&";} var f1=document.getElementById('f1').value;if(f1.length>0){s+="func2="+encodeURIComponent(f1)+"&";} s+="xmin="+coords.xStt.toPrecision(4)+"&";s+="xmax="+coords.xEnd.toPrecision(4)+"&";s+="ymin="+coords.yStt.toPrecision(4)+"&";s+="ymax="+coords.yEnd.toPrecision(4)+"&";s=s.substr(0,s.length-1);return(s);} function linkPopClose(){var pop=document.getElementById('linkpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-500px';} function onaChg(n,v){aVal=v;var div=document.getElementById('aval');div.innerHTML=v;div.style.left=(170+v*100)+'px';doGraph();} function polarClick(){polarQ=!polarQ;toggleBtn('polarBtn',polarQ);doGraph();} function toggleBtn(btn,onq){if(onq){document.getElementById(btn).classList.add("hi");document.getElementById(btn).classList.remove("lo");}else{document.getElementById(btn).classList.add("lo");document.getElementById(btn).classList.remove("hi");}} function zoomReset(){coords=new Coords(graphLt,graphTp,graphWd,graphHt,-5,-3,5,3,true);doGraph();} function doExample(n){var ex=examples[n];var s=ex[0];s=s.replace('','^');s=s.replace('','');document.getElementById('f1').innerHTML=s;document.getElementById('info').innerHTML=ex[1];gaps=ex[2];doGraph();} function ontouchstart(evt){var touch=evt.targetTouches[0];evt.clientX=touch.clientX;evt.clientY=touch.clientY;evt.touchQ=true;mouseDownListener(evt)} function ontouchmove(evt){var touch=evt.targetTouches[0];evt.clientX=touch.clientX;evt.clientY=touch.clientY;evt.touchQ=true;mouseMoveListener(evt);evt.preventDefault();} function ontouchend(evt){dragging=false;} function mouseDownListener(evt){var bRect=el.getBoundingClientRect();var mouseX=(evt.clientX-bRect.left)*(el.width/ratio/bRect.width);var mouseY=(evt.clientY-bRect.top)*(el.height/ratio/bRect.height);downX=mouseX;downY=mouseY;prevX=mouseX;prevY=mouseY;dragging=true;if(evt.preventDefault){evt.preventDefault();} else if(evt.returnValue){evt.returnValue=false;} return false;} function mouseUpListener(evt){var bRect=el.getBoundingClientRect();var mouseX=(evt.clientX-bRect.left)*(el.width/ratio/bRect.width);var mouseY=(evt.clientY-bRect.top)*(el.height/ratio/bRect.height);if(Math.abs(mouseX-downX)<2&&Math.abs(mouseY-downY)<2){coords.newCenter(mouseX,mouseY);doGraph();} dragging=false;} function mouseMoveListener(evt){var bRect=el.getBoundingClientRect();var mouseX=(evt.clientX-bRect.left)*(el.width/ratio/bRect.width);var mouseY=(evt.clientY-bRect.top)*(el.height/ratio/bRect.height);if(dragging){var moveX=prevX-mouseX;var moveY=mouseY-prevY;if(Math.abs(moveX)>1||Math.abs(moveY)>1){coords.drag(moveX,moveY);doGraph();prevX=mouseX;prevY=mouseY;}}} function onZoomChg(n,v){var scaleBy=(v*2+0.01)/currZoom;coords.scale(scaleBy);currZoom*=scaleBy;if(n==1){currZoom=1;document.getElementById('r1').value=0.5;} doGraph();} function drawPlot(plotType){switch(plotType){case "implicit":drawNewton(1);break;case "newton2":drawNewton(2);break;case "signchange":drawImplicitSign(2,plotType);break;case "shaded":drawShaded(2,plotType);break;default:} var gapsQ=false;if(gaps!=null){if(gaps.length>0){gapsQ=true;}} var breakQ=true;var prevxPix=-1;var prevyPix=-1;var yState=9;var ptNumMin;var ptNumMax;switch(plotType){case "xy":case "dydx":ptNumMin=0;ptNumMax=coords.width;break;case "polar":var revFrom=0;var revTo=4;var angle0=revFrom*6.2832;var angle1=revTo*6.2832;points=Math.min(Math.max(600,(revTo-revFrom)*250),3000);stepSize=(angle1-angle0)/points;if(stepSize==0) stepSize=1;ptNumMin=Math.floor(angle0/stepSize);ptNumMax=Math.ceil(angle1/stepSize);break;case "para":var tFrom=0;var tTo=3;var points=Math.min(Math.max(600,(tTo-tFrom)*250),3000);var stepSize=(tTo-tFrom)/points;if(stepSize==0) stepSize=1;ptNumMin=Math.floor(tFrom/stepSize);ptNumMax=Math.ceil(tTo/stepSize);break;default:} var line=[];var prevxVal=Number.NEGATIVE_INFINITY;var prevyVal=Number.NEGATIVE_INFINITY;var recipdx=1/coords.xScale;for(var ptNum=0;ptNum<=ptNumMax;ptNum++){var xVal;var yVal;var xPix;var yPix;switch(plotType){case "xy":xPix=ptNum;xVal=coords.xStt+xPix*coords.xScale;parser.setVarVal("x",xVal);yVal=parser.getVal();yPix=coords.toYPix(yVal,false);break;case "dydx":xPix=ptNum;xVal=coords.xStt+xPix*coords.xScale;parser.setVarVal("x",xVal);var thisyVal=parser.getVal();yVal=(thisyVal-prevyVal)*recipdx;prevyVal=thisyVal;break;case "polar":var angle=ptNum*stepSize;parser.setVarVal("x",angle);var radius=parser.getVal();xVal=radius*Math.cos(angle);yVal=radius*Math.sin(angle);break;case "para":xPix=ptNum;var t=coords.xStt+xPix*coords.xScale;var xy=conicVals(t);xVal=xy[0];yVal=xy[1];if(this.vals["b"]>1.1){if(yVal<-0.95&&yVal>-1.05){pt1[0]=xy[0];pt1[1]=xy[1];}}else{if(yVal<-this.vals["b"]*0.7&&yVal>-this.vals["b"]*0.8){pt1[0]=xy[0];pt1[1]=xy[1];}} break;default:} var prevbreakQ=breakQ;breakQ=false;var prevyState=yState;yState=0;if(yValcoords.yEnd) yState=1;if(yVal==Number.NEGATIVE_INFINITY){yState=-1;yVal=coords.yStt-coords.yScale*10;} if(yVal==Number.POSITIVE_INFINITY){yState=1;yVal=coords.yEnd+coords.yScale*10;} breakQ=prevyState*yState!=0;if(isNaN(yVal)){yState=9;breakQ=true;} if(gapsQ){for(var gapn=0;gapn=gaps[gapn]){yState=9;breakQ=true;}}} if(plotType=="polar"||plotType=="para"){xVal=Math.min(Math.max(coords.xStt-coords.xScale*10,xVal),coords.xEnd+coords.xScale*10);xPix=(xVal-coords.xStt)/coords.xScale;} yVal=Math.min(Math.max(coords.yStt-coords.yScale*10,yVal),coords.yEnd+coords.yScale*10);yPix=(coords.yEnd-yVal)/coords.yScale;if(breakQ){if(prevbreakQ){}else{if(yState<9){line.push([xPix,yPix]);}}}else{if(prevbreakQ){if(prevyState<9){line.push(0);line.push([prevxPix,prevyPix]);line.push([xPix,yPix]);}else{line.push(0);line.push([xPix,yPix]);}}else{line.push([xPix,yPix]);}} prevxVal=xVal;prevxPix=xPix;prevyPix=yPix;} var sttQ=true;g.beginPath();for(var i=0,len=line.length;i0){s=s.substr(0,1000);parser.radiansQ=this.radQ;parser.setVarVal('a',aVal);parser.newParse(s);g.strokeStyle=clrs[0];g.lineWidth=1.5;drawPlot('xy');} var end=new Date().getTime();var time=end-start;g.fillStyle="#000000";g.strokeStyle="#000000";g.font="bold 14px Verdana";g.textAlign="center";var anss=[];for(var i=0;i=coords.xStt&&ansthis.xEnd){temp=this.xStt;this.xStt=this.xEnd;this.xEnd=temp;} if(this.yStt>this.yEnd){temp=this.yStt;this.yStt=this.yEnd;this.yEnd=temp;} var xSpan=this.xEnd-this.xStt;if(xSpan<=0) xSpan=1e-9;this.xScale=xSpan/this.width;this.xLogScale=(Math.log(this.xEnd)-Math.log(this.xStt))/this.width;var ySpan=this.yEnd-this.yStt;if(ySpan<=0) ySpan=1e-9;this.yScale=ySpan/this.height;this.yLogScale=(Math.log(this.yEnd)-Math.log(this.yStt))/this.height;if(this.uniScaleQ&&!this.xLogQ&&!this.yLogQ){var newScale=Math.max(this.xScale,this.yScale);this.xScale=newScale;xSpan=this.xScale*this.width;var xMid=(this.xStt+this.xEnd)/2;this.xStt=xMid-xSpan/2;this.xEnd=xMid+xSpan/2;this.yScale=newScale;ySpan=this.yScale*this.height;var yMid=(this.yStt+this.yEnd)/2;this.yStt=yMid-ySpan/2;this.yEnd=yMid+ySpan/2;}};Coords.prototype.scale=function(factor,xMid,yMid){if(typeof xMid=='undefined')xMid=(this.xStt+this.xEnd)/2;this.xStt=xMid-(xMid-this.xStt)*factor;this.xEnd=xMid+(this.xEnd-xMid)*factor;if(typeof yMid=='undefined')yMid=(this.yStt+this.yEnd)/2;this.yStt=yMid-(yMid-this.yStt)*factor;this.yEnd=yMid+(this.yEnd-yMid)*factor;this.calcScale();};Coords.prototype.drag=function(xPix,yPix){this.xStt+=xPix*this.xScale;this.xEnd+=xPix*this.xScale;this.yStt+=yPix*this.yScale;this.yEnd+=yPix*this.yScale;this.calcScale();};Coords.prototype.newCenter=function(x,y){var xMid=this.xStt+x*this.xScale;var xhalfspan=(this.xEnd-this.xStt)/2;this.xStt=xMid-xhalfspan;this.xEnd=xMid+xhalfspan;var yMid=this.yEnd-y*this.yScale;var yhalfspan=(this.yEnd-this.yStt)/2;this.yStt=yMid-yhalfspan;this.yEnd=yMid+yhalfspan;this.calcScale();};Coords.prototype.fitToPts=function(pts,borderFactor){for(var i=0;i=5){if(majorQ){return(5*pow10);}else{return(2*pow10);}} if(mantissa>=2){if(majorQ){return(2*pow10);}else{return(1*pow10);}} if(mantissa>=1){if(majorQ){return(1*pow10);}else{return(0.2*pow10);}} if(majorQ){return(1*pow10);}else{return(0.2*pow10);}};Coords.prototype.xTickInterval=function(tickDensity,majorQ){return this.tickInterval((this.xEnd-this.xStt)/tickDensity,majorQ);};Coords.prototype.yTickInterval=function(tickDensity,majorQ){return this.tickInterval((this.yEnd-this.yStt)/tickDensity,majorQ);};function Graph(g,coords){this.g=g;this.coords=coords;this.xLinesQ=true;this.yLinesQ=true;this.xValsQ=true;this.yValsQ=true;this.dirClrs=['#8888ff','red'];this.skewQ=false;} Graph.prototype.drawGraph=function(){if(coords.xLogQ){this.drawLinesLogX();}else{if(this.xLinesQ){this.drawLinesX();}} if(coords.yLogQ){this.drawLinesLogY();}else{if(this.yLinesQ){this.drawLinesY();}}};Graph.prototype.drawLinesX=function(){var xAxisPos=coords.toYPix(0);var yAxisPos=coords.toXPix(0);var numAtAxisQ=(yAxisPos>=0&&yAxisPos0&&xAxisPos=0&&yAxisPos=0&&xAxisPos=0&&xAxisPos="0"&&c<="9"){thisType="N";}else{if(this.operators.indexOf(c)>=0){if(c=="-"){thisType="-";}else{thisType="O";}}else{if(c=="."||c==this.Variable){thisType="N";}else{thisType="C";}} if(c=="("){thisType="(";} if(c==")"){thisType=")";}} x+=thisType;if(prevType=="("&&thisType=="-"){y+="0";} if(OpenQ){switch(thisType){case "N":break;default:y+=")";OpenQ=false;}} if(prevType=="O"&&thisType=="-"){y+="(0";OpenQ=true;} y+=c;prevType=thisType;} if(OpenQ){y+=")";OpenQ=false;} return(y);};Parser.prototype.fixImplicitMultply=function(s){var x=s+"\n";var y="";var prevType="?";var prevName="";var thisType="?";var thisName="";for(var i=0;i="0"&&c<="9"){thisType="N";}else{if(this.operators.indexOf(c)>=0){thisType="O";thisName="";}else{thisType="C";thisName+=c;} if(c=="("){thisType="(";} if(c==")"){thisType=")";}} x+=thisType;if(prevType=="N"&&thisType=="C"){y+="*";thisName="";} if(prevType=="N"&&thisType=="("){y+="*";} if(prevType==")"&&thisType=="("){y+="*";} if(thisType=="("){switch(prevName){case "i":case "pi":case "e":case "a":case this.Variable:y+="*";break;}} y+=c;prevType=thisType;prevName=thisName;} return(y);};Parser.prototype.reset=function(){this.tempNode=[];this.errMsg="";};Parser.prototype.parse=function(s){if(s==""){return new MathNode("real","0",this.radiansQ);} if(isNumeric(s)){return new MathNode("real",s,this.radiansQ);} if(s.charAt(0)=="$"){if(isNumeric(s.substr(1))){return this.tempNode[Number(s.substr(1))];}} var sLo=s.toLowerCase();if(sLo.length==1){if(sLo>="a"&&sLo<="z"){return new MathNode("var",sLo,this.radiansQ);}} switch(sLo){case "pi":return new MathNode("var",sLo,this.radiansQ);break;} var bracStt=s.lastIndexOf("(");if(bracStt>-1){var bracEnd=s.indexOf(")",bracStt);if(bracEnd<0){this.errMsg+="Missing ')'\n";return new MathNode("real","0",this.radiansQ);} var isParam=false;if(bracStt==0){isParam=false;}else{var prefix=s.substr(bracStt-1,1);isParam=this.operators.indexOf(prefix)<=-1;} if(!isParam){this.tempNode.push(this.parse(s.substr(bracStt+1,bracEnd-bracStt-1)));return this.parse(s.substr(0,bracStt)+"$"+(this.tempNode.length-1).toString()+s.substr(bracEnd+1,s.length-bracEnd-1));}else{var startM=-1;for(var u=bracStt-1;u>-1;u--){var found=this.operators.indexOf(s.substr(u,1));if(found>-1){startM=u;break;}} nnew=new MathNode("func",s.substr(startM+1,bracStt-1-startM),this.radiansQ);nnew.addchild(this.parse(s.substr(bracStt+1,bracEnd-bracStt-1)));this.tempNode.push(nnew);return this.parse(s.substr(0,startM+1)+"$"+(this.tempNode.length-1).toString()+s.substr(bracEnd+1,s.length-bracEnd-1));}} var k;var k1=s.lastIndexOf("+");var k2=s.lastIndexOf("-");if(k1>-1||k2>-1){if(k1>k2){k=k1;var nnew=new MathNode("op","add",this.radiansQ);nnew.addchild(this.parse(s.substr(0,k)));nnew.addchild(this.parse(s.substr(k+1,s.length-k-1)));return nnew;}else{k=k2;nnew=new MathNode("op","sub",this.radiansQ);nnew.addchild(this.parse(s.substr(0,k)));nnew.addchild(this.parse(s.substr(k+1,s.length-k-1)));return nnew;}} k1=s.lastIndexOf("*");k2=s.lastIndexOf("../index.html");if(k1>-1||k2>-1){if(k1>k2){k=k1;nnew=new MathNode("op","mult",this.radiansQ);nnew.addchild(this.parse(s.substr(0,k)));nnew.addchild(this.parse(s.substr(k+1,s.length-k-1)));return nnew;}else{k=k2;nnew=new MathNode("op","div",this.radiansQ);nnew.addchild(this.parse(s.substr(0,k)));nnew.addchild(this.parse(s.substr(k+1,s.length-k-1)));return nnew;}} k=s.indexOf("^");if(k>-1){nnew=new MathNode("op","pow",this.radiansQ);nnew.addchild(this.parse(s.substr(0,k)));nnew.addchild(this.parse(s.substr(k+1,s.length-k-1)));return nnew;} if(isNumeric(s)){return new MathNode("real",s,this.radiansQ);}else{if(s.length==0){return new MathNode("real","0",this.radiansQ);}else{this.errMsg+="'"+s+"' is not a number.\n";return new MathNode("real","0",this.radiansQ);}}};function MathNode(typ,val,radQ){this.tREAL=0;this.tVAR=1;this.tOP=2;this.tFUNC=3;this.radiansQ=true;this.setNew(typ,val,radQ);} MathNode.prototype.setNew=function(typ,val,radQ){this.radiansQ=typeof radQ!=='undefined'?radQ:true;this.clear();switch(typ){case "real":this.typ=this.tREAL;this.r=Number(val);break;case "var":this.typ=this.tVAR;this.v=val;break;case "op":this.typ=this.tOP;this.op=val;break;case "func":this.typ=this.tFUNC;this.op=val;break;} return(this);};MathNode.prototype.clear=function(){this.r=1;this.v="";this.op="";this.child=[];this.childCount=0;};MathNode.prototype.addchild=function(n){this.child.push(n);this.childCount++;return(this.child[this.child.length-1]);};MathNode.prototype.getLevelsHigh=function(){var lvl=0;for(var i=0;i0){var parq=false;if(this.op=="add")parq=true;if(this.op=="sub")parq=true;if(prevop=="div")parq=true;if(noparq)parq=false;if(this.typ==this.tFUNC)parq=true;if(this.typ==this.tOP){}else{s+=this.fmt(true);} if(parq)s+="(";for(var i=0;i0)s+=this.fmt();s+=this.child[i].walkFmta(false,this.op);if(this.typ==this.tFUNC||(parq&&i>0)){s+=")";}}}else{s+=this.fmt();if(prevop=="sin"||prevop=="cos"||prevop=="tan"){if(this.radiansQ){s+=" rad";}else{s+="°";}}} return s;};MathNode.prototype.walkNodesFmt=function(level){var s="";for(var i=0;i2){f*=i;} return f;} function isNumeric(n){return!isNaN(parseFloat(n))&&isFinite(n);} CanvasRenderingContext2D.prototype.drawArrow=function(x0,y0,totLen,shaftHt,headLen,headHt,angle,sweep,invertQ){var g=this;var pts=[[0,0],[-headLen,-headHt/2],[-headLen+sweep,-shaftHt/2],[-totLen,-shaftHt/2],[-totLen,shaftHt/2],[-headLen+sweep,shaftHt/2],[-headLen,headHt/2],[0,0]];if(invertQ){pts.push([0,-headHt/2],[-totLen,-headHt/2],[-totLen,headHt/2],[0,headHt/2]);} for(var i=0;i