【問題】
比較a=0.6^0.9 b=0.6^1.5 c=1.5^0.6的大小
【解答】
指數函數y=0.6^x是減函數,因為0.9<1.5,所以0.6^0.9>0.6^1.5,即a>b;
指數函數y=1.5^x是增函數,1.5^0.6>1.5^0=1>0.6^0.9,即c>a;
綜上,得出c>a>b的結論。
【圖形】
繪出兩指數函數y=0.6^x和y=1.5^x,然后標出a,b,c,1的位置,四者的大小關系可一目了然。
【代碼】
<!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <head><title>UNASSIGNED</title><style type="text/css">.centerlize{margin:0 auto;border:0px solid red;width:1200px;height:600px;}</style></head><body οnlοad="draw();"><div class="centerlize"><canvas id="myCanvas" width="10px" height="10px" style="border:1px dashed black;">如果看到這段文字說您的瀏覽器尚不支持HTML5 Canvas,請更換瀏覽器再試.</canvas></div></body> </html> <script type="text/javascript"> <!-- /***************************************************************** * 將全體代碼拷貝下來,粘貼到文本編輯器中,另存為.html文件, * 再用chrome瀏覽器打開,就能看到動畫效果。 ******************************************************************/// 系統常量定義處 const TITLE="比較a=0.6^0.9 b=0.6^1.5 c=1.5^0.6的大小"; // 圖像標題 const WIDTH=1200; // 畫布寬度 const HEIGHT=600; // 畫布高度 const ScaleUnit=100; // 縮放比例// 系統變量定義處 var context=0; // 畫布環境 var stage; // 舞臺對象 var timeElapsed=0; // 動畫運作的的時間 const TIME_END=10000; // 動畫運作的期限//------------------------------- // Canvas開始運作,由body_onload調用 //------------------------------- function draw(){document.title=TITLE;// 畫圖前初始化var canvas=document.getElementById('myCanvas'); canvas.width=WIDTH;canvas.height=HEIGHT; context=canvas.getContext('2d'); // 進行屏幕坐標系到笛卡爾坐標系的變換// 處置完成前,原點在左上角,向右為X正向,向下為Y的正向// 處置完畢后,原點移動到畫布中央,向右為X正向,向上為Y的正向context.translate(WIDTH/2,HEIGHT/2);context.rotate(Math.PI);context.scale(-1,1);// 初始化舞臺stage=new Stage();// 開始動畫animate(); };//------------------------------- // 畫圖 //------------------------------- function animate(){ timeElapsed+=1;// 時間每輪增加1stage.update(timeElapsed);stage.paintBg(context);stage.paint(context);if(timeElapsed<TIME_END){ window.requestAnimationFrame(animate);} }//------------------------------- // 舞臺對象定義處 //------------------------------- function Stage(){var obj=new Object;obj.curve1={name:"曲線:y=0.6^x",xEnd:2.5,x:-2.5,y:0,color:"maroon",setY:function(x){this.y=Math.pow(0.6,x);// 解析式// 制成坐標let coord={"x":x,"y":this.y};this.pts0.push(coord);},"pts0":[],};obj.curve2={name:"曲線:y=1.5^x",xEnd:2.5,x:-2.5,y:0,color:"orange",setY:function(x){this.y=Math.pow(1.5,x);// 解析式// 制成坐標let coord={"x":x,"y":this.y};this.pts0.push(coord);},"pts0":[],}; // 隨時間更新位置obj.update=function(t){// 記錄曲線1的xy值if(obj.curve1.x<obj.curve1.xEnd){obj.curve1.x+=0.01;obj.curve1.setY(obj.curve1.x);}// 記錄曲線2的xy值if(obj.curve2.x<obj.curve2.xEnd){obj.curve2.x+=0.01;obj.curve2.setY(obj.curve2.x);} };// 畫前景obj.paint=function(ctx){ // 曲線一名稱drawText(ctx,this.curve1.name,400,225,this.curve1.color,18);// 曲線一當前點坐標drawText(ctx,"當前 X:"+this.curve1.x.toFixed(3)+" Y:"+this.curve1.y.toFixed(3),400,205,this.curve1.color,18);// 繪制曲線一paintCurve(ctx,this.curve1.color,this.curve1.pts0);//var mm=findMaxMin(this.curve1.pts0);//markMaxMin(ctx,mm,this.curve1.color);// 曲線二名稱drawText(ctx,this.curve2.name,400,175,this.curve2.color,18);// 曲線二當前點坐標drawText(ctx,"當前 X:"+this.curve2.x.toFixed(3)+" Y:"+this.curve2.y.toFixed(3),400,155,this.curve2.color,18);// 繪制曲線二paintCurve(ctx,this.curve2.color,this.curve2.pts0);//var mm=findMaxMin(this.curve2.pts0);//markMaxMin(ctx,mm,this.curve2.color);// a,b比較paintPoint(ctx,0.9,Math.pow(0.6,0.9),"a","black"); paintPoint(ctx,1.5,Math.pow(0.6,1.5),"b","black");// c,1比較paintPoint(ctx,0.6,Math.pow(1.5,0.6),"c","black");paintPoint(ctx,0,Math.pow(1.5,0),"1","black");};// 畫背景obj.paintBg=function(ctx){// 清屏ctx.clearRect(-600,-300,1200,600);ctx.fillStyle="white";ctx.fillRect(-600,-300,1200,600);// 畫X軸drawAxisX(ctx,-600,600,50);// 畫Y軸drawAxisY(ctx,-300,300,50);// 畫網格線drawGrid(ctx,-600,-300,50,1200,600,50,"lightGrey");// 左上角標題var metrics = ctx.measureText(TITLE);var textWidth = metrics.width;drawText(ctx,TITLE,-WIDTH/2+textWidth,HEIGHT/2-30,"grey",18);// 右下角作者,日期const waterMarkTxt="逆火原創@"+(new Date()).toLocaleDateString();metrics = ctx.measureText(waterMarkTxt);textWidth = metrics.width;drawText(ctx,waterMarkTxt,WIDTH/2-textWidth,-HEIGHT/2,"lightGrey",16);};return obj; }// 描繪并標識一個點 function paintPoint(ctx,x,y,text,color){ctx.beginPath();ctx.arc(x*ScaleUnit,y*ScaleUnit,4,0,Math.PI*2,false);ctx.closePath();ctx.strokeStyle=color;ctx.stroke();drawText(ctx,text,x*ScaleUnit+9,y*ScaleUnit-5,color,12); }// 連點成線畫曲線 function paintCurve(ctx,color,cds){ctx.strokeStyle = color;ctx.beginPath(); for(var i=0; i<cds.length; i++){let y=cds[i].y;if(Math.abs(cds[i].y*ScaleUnit)<300){ctx.lineTo(cds[i].x*ScaleUnit,cds[i].y*ScaleUnit);}} ctx.stroke(); }// 找到坐標數組的最大最小值 function findMaxMin(cds){if(cds.length<1){return null;}var retval={max:-10000,max_x:0,min:10000,min_x:0};for(var i=0;i<cds.length;i++){var y=cds[i].y;if(y>retval.max){retval.max=y;retval.max_x=cds[i].x;}if(y<retval.min){retval.min=y;retval.min_x=cds[i].x;}} return retval; }// 繪出最大最小值 function markMaxMin(ctx,mm,color){if(mm==null){return;}// 最大值var x=mm.max_x;var y=mm.max;ctx.strokeStyle=color;ctx.beginPath();ctx.arc(x*ScaleUnit,y*ScaleUnit,5,0,Math.PI*2,false);ctx.closePath();ctx.stroke();var text="max@x="+x.toFixed(3)+" y="+y.toFixed(3);drawText(ctx,text,x*ScaleUnit,y*ScaleUnit,color,12);// 最小值var x=mm.min_x;var y=mm.min;ctx.strokeStyle=color;ctx.beginPath();ctx.arc(x*ScaleUnit,y*ScaleUnit,5,0,Math.PI*2,false);ctx.closePath();ctx.stroke();var text="min@x="+x.toFixed(3)+" y="+y.toFixed(3);drawText(ctx,text,x*ScaleUnit,y*ScaleUnit,color,12); }// 定點畫實心圓 function drawSolidCircle(ctx,x,y,r,color){ctx.save();ctx.beginPath();ctx.arc(x,y,r,0,2*Math.PI);ctx.fillStyle=color;ctx.fill();ctx.stroke();ctx.restore(); }// 兩點之間畫線段 function drawLine(ctx,x1,y1,x2,y2,color){ctx.save();ctx.lineWidth=0.25;ctx.strokeStyle=color;ctx.fillStyle=color;ctx.beginPath();ctx.moveTo(x1,y1);ctx.lineTo(x2,y2);ctx.stroke();ctx.closePath();ctx.restore(); }// 畫橫軸 function drawAxisX(ctx,start,end,step){ctx.save();ctx.lineWidth=0.25;ctx.strokeStyle='navy';ctx.fillStyle='navy';// 畫軸ctx.beginPath();ctx.moveTo(start, 0);ctx.lineTo(end, 0);ctx.stroke();ctx.closePath();// 畫箭頭ctx.beginPath();ctx.moveTo(end-Math.cos(getRad(15))*10, Math.sin(getRad(15))*10);ctx.lineTo(end, 0);ctx.lineTo(end-Math.cos(getRad(15))*10, -Math.sin(getRad(15))*10);ctx.stroke();ctx.closePath();// 畫刻度var x,y;y=5;for(x=start;x<end;x+=step){ctx.beginPath();ctx.moveTo(x, 0);ctx.lineTo(x, y);ctx.stroke();ctx.closePath();drawText(ctx,x/ScaleUnit+"",x,y-20,"navy",12);}ctx.restore(); }// 畫縱軸 function drawAxisY(ctx,start,end,step){ctx.save();ctx.lineWidth=0.5;ctx.strokeStyle='navy';ctx.fillStyle='navy';// 畫軸ctx.beginPath();ctx.moveTo(0, start);ctx.lineTo(0, end);ctx.stroke();ctx.closePath();// 畫箭頭ctx.beginPath();ctx.moveTo(Math.sin(getRad(15))*10, end-Math.cos(getRad(15))*10);ctx.lineTo(0, end);ctx.lineTo(-Math.sin(getRad(15))*10, end-Math.cos(getRad(15))*10);ctx.stroke();ctx.closePath();// 畫刻度var x,y;x=5;for(y=start;y<end;y+=step){ctx.beginPath();ctx.moveTo(x, y);ctx.lineTo(0, y);drawText(ctx,y/ScaleUnit+"",x-15,y,"navy",12);ctx.stroke();ctx.closePath();}ctx.restore(); }// 畫網格線 function drawGrid(ctx,x1,y1,step1,x2,y2,step2,color){ctx.save();ctx.lineWidth=0.5;ctx.strokeStyle=color;ctx.fillStyle=color;ctx.setLineDash([4,4]);// 設置虛線var x,y;for(x=x1;x<x2;x+=step1){ctx.beginPath();ctx.moveTo(x, y1);ctx.lineTo(x, y2);ctx.stroke();ctx.closePath();}for(y=y1;y<y2;y+=step2){ctx.beginPath();ctx.moveTo(x1, y);ctx.lineTo(x2, y);ctx.stroke();ctx.closePath();}ctx.restore(); }//------------------------------- // 角度得到弧度 //------------------------------- function getRad(degree){return degree/180*Math.PI; }//------------------------------- // 得到顏色 //------------------------------- function getColor(index){var arr=["aqua"/* aqua湖綠色*/,"black"/* black黑色*/,"blue"/* blue藍色*/,"fuchsia"/* fuchsia 紫紅*/,"green"/* green 綠色*/,"grey"/* grey 草木灰*/,"lime"/* lime 亮綠色*/,"maroon"/* maroon 棕色*/,"navy"/* navy 海軍藍*/,"orange"/* orange 橙色*/,"purple"/* purple 紫色*/,"red"/* red 大紅*/, "skyblue"/* skyblue 天藍*/,"teal"/* teal 藍綠色*/,"yellow"/* yellow 亮黃*/,"#aa0000"/* #aa0000 鐵銹紅*/, ];if(index>arr.length){index=index % arr.length;}return arr[index]; }//------------------------------------- // 繪制文字,指定顏色 // ctx:繪圖環境 // text:文字 // x,y:坐標 // color:顏色 // size:字體大小 //------------------------------------- function drawText(ctx,text,x,y,color,size){ctx.save();ctx.translate(x,y)ctx.rotate(getRad(180))ctx.scale(-1,1)ctx.textBaseline="bottom";ctx.textAlign="center";ctx.fillStyle=color;ctx.font = size+"px consolas";ctx.fillText(text,0,0);ctx.restore(); }// JS開立方 function kaiLiFang(x){if(x>0){return Math.pow(x,1/3);}else{return -Math.pow(-x,1/3);} } //--> /************************************** 《贈友》 --杜運夑我有眼淚給別人,但不愿為自己痛哭;我沒有使自己適合于這世界,也沒有美麗的自辟的國土,就只好永遠渴望:為希望而生;在希望里死去,終于承認了不知道生命;接受了它又揮霍掉,只是歷史的工具,長路上的一粒沙,所以拼命擺脫那黑影,而他們因此譏笑我;這就選擇了寂寞,熱鬧的寂寞,用笑聲騙自己,飄浮在庸俗生活的渦流里,而漸漸,我就說,我是個庸俗主義者,無心痛哭。 **************************************/ </script>