Try   HackMD

用gnuplot繪製圓形駐波

作者:王一哲
日期:2012/4/9


前言

現在出版社都會找各校的老師寫一些專刊,最近看到一篇蠻有趣的文章:

徐世昌與徐國誠(2012)。用Excel操縱電子的駐波。全華TopLine物理專刊5,1-8。

文章中是利用Excel,用描點的方式把圓形駐波畫出來。於是我就想到之前用過的函數繪圖軟體 gnuplot,用它應該也能做到同樣的效果,而且會比描點的方式還方便,今天花了幾個小時終於把它弄出來了。


繪圖方法

首先,我們需要畫出一個圓形,接著在圓周上畫兩個反相的sin波,這兩個函數可寫成

r=R+Asin(nθ)

r=RAsin(nθ)

以下是我用來繪製圖形的gnuplot檔:

# 用來繪製圓形駐波 # Author: 王一哲 # Date: April 9, 2012 reset #恢復預設值 set size square #設定圖形為方形 set key off #不顯示圖例 unset border #不顯示邊框 unset xtics #不顯示x軸 unset ytics #不顯示y軸 set style line 1 linecolor rgb "red" linewidth 2 set style line 2 linecolor rgb "green" linewidth 2 set style line 3 linecolor rgb "blue" linewidth 2 #設定線條顏色及寬度,上一行可用縮寫 lc=linecolor lw=linewidth #rgb可用的顏色至少有red, green, blue, yellow, gold, purple, sea-green set style increment user #線條格式採用自訂值 set polar #設定為極坐標繪圖,預設的變數為"t" n=9 #設定主量子數 R=10 #設定圓半徑 A=R*0.1 #設定圓周上起伏的程度 set title "N=".n #"設定標題為"N=n", n為主量子數 f1(t)=R+A*sin(n*t) #設定在圓周上起伏的函數1 f2(t)=R-A*sin(n*t) #設定在圓周上起伏的函數2,與f1(t)反相 f3(t)=R #圓形 set terminal png #設定輸出格式為png set output "circle-sw.png" #設定輸出檔名 plot f1(t),f2(t),f3(t) set terminal svg #設定輸出格式為svg set output "circle-sw.svg" #設定輸出檔名 plot f1(t),f2(t),f3(t)

若將以上的內容另存為circle-sw.gp,接著只要在文字介面中輸入

gnuplot circle-sw.gp

便會自動畫出 circle-sw.pngcircle-sw.svg 兩個檔案。以下是我畫出來的圖片

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 1

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 2

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 3

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 4

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 5

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 6

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 7

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 8

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
n = 9

延伸閱讀

若對gnuplot有興趣的讀者,可以參考以下幾個網頁

  1. gnuplot官方網頁 http://www.gnuplot.info/
  2. gnuplot的範例 http://gnuplot.sourceforge.net/demo/


tags:軟體gnuplot