var w,h,ratio,i,s,el,g,div,dragQ,game,my={};function compoundinterestMain(mode){my.version='0.61';typ=typeof mode!=='undefined'?mode:'longitudinal';w=400;my.graphWd=w;my.graphHt=300;xstt=-1;xend=11;ystt=-100;yend=4000;my.calcType="FV";my.decPlaces=3;my.rate=0.1;var s='';s+='
';my.comps=[{name:'1',title:'None'},{name:'2',title:'Semiannually (2)'},{name:'4',title:'Quarterly (4)'},{name:'12',title:'Monthly (12)'},{name:'365',title:'Daily (365)'},{name:'C',title:'Continuous'}];var compStr='';compStr+='
';compStr+='
Compounding:
';compStr+=getDropdownHTML(my.comps,'calcDo','compSel');compStr+=' ⇒ ';compStr+='
';s+='
';my.inps=[{name:'PV',title:'Present Value',formula:'PV = FV(1+r)n',val:1000,dec:2},{name:'r',title:'Interest Rate',formula:'r = (FV/PV)(1/n) − 1',val:10,dec:3},{name:'n',title:'Periods',formula:'n = ln(FV / PV)ln(1 + r)',val:5,dec:2},{name:'FV',title:'Future Value',formula:'FV = PV (1+r)n',val:1610,dec:2}];my.styles=['Know','Want'];for(var i=0;i';s+='
'+inp.title+' ('+inp.name+')'+':
';s+='
';s+='';s+='
';s+=getRadioHTML('Want','want'+i,my.styles,'wantChg',i);s+='
';if(i==1)s+=compStr;} s+='
';s+='
';s+='';s+='
';s+='
';s+='';s+='';s+='
';s+='
© 2017 MathsIsFun.com v'+my.version+'
';s+='';document.write(s);el=document.getElementById('canvas1');ratio=3;el.width=w*ratio;el.height=my.graphHt*ratio;el.style.width=w+"px";el.style.height=my.graphHt+"px";g=el.getContext("2d");g.setTransform(ratio,0,0,ratio,0,0);dragType='';this.clrs=[["Blue",'#0000FF'],["Red",'#FF0000'],["Black",'#000000'],["Green",'#00cc00'],["Orange",'#FFA500'],["Slate Blue",'#6A5ACD'],["Lime",'#00FF00'],["Spring Green",'#00FF7F'],["Teal",'#008080'],["Gold",'#ffd700'],["Med Purple",'#aa00aa'],["Light Blue",'#ADD8E6'],["Navy",'#000080'],["Purple",'#800080'],["Dark SeaGreen",'#8FBC8F']];clrNum=0;console.log("typ",typ);wantChg(3,1);calcDo();} function wantChg(n,j){console.log("chgWant",n,j);for(var i=0;i';for(var i=0;i'+opts[i].title+'';} s+='';return s;} function getRadioHTML(prompt,id,lbls,func,n){var s='';s+='
';for(var i=0;i';s+='';} s+='
';return s;} function drawPlot(ClearQ,obj,Col){g.clearRect(0,0,g.canvas.width,g.canvas.height);xstt=0;xend=my.n;ystt=my.PV;yend=my.FV;scaleCalcs();drawGraph();drawXY(ClearQ,obj,Col);} function scaleCalcs(){if(xstt>xend){temp=xstt;xstt=xend;xend=temp;} if(ystt>yend){temp=ystt;ystt=yend;yend=temp;} xspan=xend-xstt;if(0>=xspan){xspan=0.1;} xscale=xspan/my.graphWd;yspan=yend-ystt;if(0>=yspan){yspan=0.1;} xstt-=1;xend+=1;xspan=xend-xstt;xscale=xspan/my.graphWd;ystt=ystt-yspan*0.1;yend=yend+yspan*0.1;yspan=yend-ystt;yscale=yspan/my.graphHt;} function drawGraph(){NumAtAxisQ=true;xaxispos=yend/yscale;yaxispos=(-xstt)/xscale;TickFreq=2;TickLevels=2;LogSpan=Math.log(xspan/TickFreq)/2.302585092994046;xMajorTick=Math.pow(10,Math.floor(LogSpan));if(LogSpan-Math.floor(LogSpan)<0.3){xMajorTick=xMajorTick/2;} xMinorTick=xMajorTick/5;if(Math.abs(xscale/yscale-1)<0.1){yMajorTick=xMajorTick;}else{LogSpan=Math.log(yspan/TickFreq)/2.302585092994046;yMajorTick=Math.pow(10,Math.floor(LogSpan));if(LogSpan-Math.floor(LogSpan)<0.3){yMajorTick=yMajorTick/2;}} yMinorTick=yMajorTick/5;TickLevel=0;while(TickLevel=x){i=(x-xstt)/xscale;g.moveTo(i,0);g.lineTo(i,my.graphHt);if(TickLevel==0){g.font="15px Georgia";g.textAlign='center';g.fillText(x,i,my.graphHt-5);} x=x+xTick;} var y=Math.ceil(ystt/yTick)*yTick;while(yend>=y){j=(yend-y)/yscale;g.moveTo(0,j);g.lineTo(my.graphWd,j);if(TickLevel==0){g.font="15px Georgia";g.textAlign='left';g.fillText(y,5,j+5);} y=y+yTick;} g.stroke();TickLevel++;} g.strokeStyle='rgba(0,0,0,1)';g.lineWidth=3;g.beginPath();g.moveTo(0,0);g.lineTo(0,my.graphHt);g.lineTo(my.graphWd,my.graphHt);g.lineTo(my.graphWd,0);g.lineTo(0,0);g.stroke();} function drawXY(ClearQ,obj,Col){g.strokeStyle='rgba(0,0,255,1)';g.lineWidth=2;BreakQ=true;Previ=-1;YState=9;PV=my.PV;FV=my.FV;IR=my.rate;NP=my.n;i=0;while(my.graphWd>=i){var xval=i*xscale+xstt;yval=PV*Math.pow(1+IR,xval);PrevBreakQ=BreakQ;BreakQ=false;PrevYState=YState;YState=0;if(yvalyend){YState=1;} if(yval==Number.NEGATIVE_INFINITY){YState=-1;yval=ystt-yscale*10;} if(yval==Number.POSITIVE_INFINITY){YState=1;yval=yend+yscale*10;} if(PrevYState*YState==0){BreakQ=false;}else{BreakQ=true;} if(isNaN(yval)){YState=9;BreakQ=true;} yval=Math.min(yend+yscale*10,Math.max(yval,ystt-yscale*10));j=(yend-yval)/yscale;if(BreakQ){if(!PrevBreakQ){if(YState<9){g.lineTo(i,j);}}}else if(PrevBreakQ){if(PrevYState<9){g.moveTo(Previ,Prevj);g.lineTo(i,j);}else{g.moveTo(i,j);}}else{g.lineTo(i,j);} Previ=i;Prevj=j;i=i+1;} g.stroke();} function enuffDigits(x,x0,x1){dx=Math.abs(x1-x0);digits=3-Math.round(Math.log(dx)/2.302585092994046);if(digits<10){factor=Math.pow(10,digits);newx=Math.round(x*factor)/factor;}else{newx=x;} return newx;} function fmt(num,digits){if(num==Number.POSITIVE_INFINITY)return "undefined";if(num==Number.NEGATIVE_INFINITY)return "undefined";num=Number(num.toFixed(digits));if(Math.abs(num)<1e-15)num=0;return num;}