2011年10月26日 星期三

廣義相對論(一) 最幸運的想法

當時我正坐在伯恩專利局的椅子上,突然靈光一現,想到如果有人掉落下來,將不會感覺到自己的重量。
wiki 表示:
General relativity generalizes special relativity and Newton's law of universal gravitation, providing a unified description of gravity as a geometric property of space and time, or spacetime.

In particular, the curvature of spacetime is directly related to the four-momentum (mass-energy and linear momentum) of whatever matter and radiation are present. The relation is specified by the Einstein field equations, a system of partial differential equations.

接下來的重要工作,就是推導 Einstein field equations,然後根據方程式,去解釋 gravitational time dilation and frequency shift,light deflection and gravitational time delay,gravitational waves,orbital effects and the relativity of direction 等等物理現象。

不知道我有沒有能力可以理解這一切,希望是可以。

2011年10月25日 星期二

[Java] JAX-WS Example

Reference:
  1. JAX-WS Five Minute Tutorial
  2. JAX-WS Deployment Five Minute Tutorial
I cannot write this article without the above reference. Thank you very much, Mohammad Juma!

Run Under Eclipse:
  1. New a Dynamic Web Project.
  2. Create an endpoint interface:
    package test;
    
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    @WebService
    public interface TestService {
        @WebMethod 
        String sayHello(String name);
        
        @WebMethod 
        Status getStatus();
    }
    
    package test;
    
    public enum Status {
        Started, 
        Stopped
    }
    
  3. Implement the interface:
    package test;
    
    import javax.jws.WebService;
    
    @WebService(endpointInterface = "test.TestService")
    
    public class TestServiceImpl implements TestService {
        @Override
        public String sayHello(String name) {
            return "Hello, Welcom to jax-ws " + name;
        }
        
        @Override
        public Status getStatus() {
            return Status.Started;
        }
    }
    
  4. Create endpoint publisher:
    package test;
    
    import javax.xml.ws.Endpoint;
    
    public class Main {
    
        public static void main(String[] args) {
            Endpoint.publish("http://localhost:8888/TestService", new TestServiceImpl());
        }
    
    }
    
  5. Run as Java application. Please check wsdl: http://localhost:8888/TestService?wsdl, or check http://localhost:8888/TestService. Here is the screenshot:

Deployment on Application Server:
Just follow the previous session except running. We need extra steps to complete our task.
  1. Execute
    cd YOUR_PROJECT_HOME
    wsgen -s src -d build/classes -cp build/classes test.TestServiceImpl
    
    in the command prompt. We will see 4 class files (GetStatus, GetStatusResponse, SayHello and SayHelloResponse) in YOUR_PROJECT_HOME\build\classes\test\jaxws and 4 java files (the same) in YOUR_PROJECT_HOME\src\test\jaxws.
  2. Create web.xml under YOUR_PROJECT_HOME\WebContent\WEB-INF:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
       <listener>
         <listener-class>
            com.sun.xml.ws.transport.http.servlet.WSServletContextListener
         </listener-class>
       </listener>
       <servlet>
          <servlet-name>TestService</servlet-name>
          <servlet-class>
            com.sun.xml.ws.transport.http.servlet.WSServlet
          </servlet-class>
    
       </servlet>
       <servlet-mapping>
         <servlet-name>TestService</servlet-name>
         <url-pattern>/TestService</url-pattern>
       </servlet-mapping>
    </web-app>
    
  3. Create sun-jaxws.xml under YOUR_PROJECT_HOME\WebContent\WEB-INF:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
      <endpoint
         name="TestService"
         implementation="test.TestServiceImpl"
         url-pattern="/TestService"/>
    </endpoints> 
    
  4. Copy all JARs under jaxws-ri-2.2\lib to YOUR_PROJECT_HOME\WebContent\WEB-INF\lib. To get the lastest JAX-WS reference implementation, visit http://jax-ws.java.net/.
  5. Export the whole project as a WAR file. 
  6. To run WAR files in Tomcat, refer to my blog.
  7. Link to http://localhost:8888/Test/TestService. Everything should be OK. The following is the soapUI screenshot:
Muchas gracias! Mohammad Juma!

2011年10月23日 星期日

朝聖北插天山 - 找不到登山口

時間:2011年10月23日 (日)

人員:摸摸、我

天氣:晴朗多雲

預計路線:滿月圓 → 東滿步道 → 北插登山口 → 水源地 → 木屋遺址 → 北插天山(原路來回)

實際路線:滿月圓 → 滿月圓瀑布 → 小樂佩鞍部(H1405M) → 多崖山 → 北插天山 → 木屋遺址 → 水源地 → 北插登山口 → 東滿步道 → 滿月圓

這次攜帶的裝備:
  • ㄉㄧㄠ山小包包:特大號垃圾袋2個、緊急求生毯、20公尺長的3mm營繩、地布、打火機、電火布、腳踏車內胎(火種)
  • 醫護小包包:個人隨身用藥、普拿疼、腹瀉藥物
  • 登山三寶 (森林指北針、不夠詳細的地圖、高度計)
  • 保暖:兩截式的雨衣、雨褲1套、禦寒外套、備用排汗內衣、內褲、備用登山襪、耐熱登山水瓶、800ml熱水瓶(已裝滿水)、爐頭、瓦斯罐、2個鈦鍋、擋風板
  • 找路:LED頭燈、備用電池、寫紀錄用的紙和筆(這次以為路很好找,所以沒記,錯誤示範)、棉質工作手套
  • 求救:手機及手機的備用電池、低音哨(聲音傳的遠)
  • 食物:飯糰、饅頭、泡麵、葡萄乾、水梨、五穀雜糧沖泡包、飲水2400ml、鹽巴、筷子
  • 其他:私人證件(身分證件及健保卡)、現金、悠遊卡、面紙4包
  • 選用裝備:登山杖、折刀
有時候想偷懶背少一點,偏偏我是貪生怕死之輩,只好多背點確保安全。實際上,這次用到:登山三寶、耐熱登山水瓶、800ml熱水瓶、鈦鍋蓋子、LED頭燈、饅頭、葡萄乾、水梨、飲水、登山杖、折刀。

印象中的紀錄:
  • 0600 今天起了大早,東西收一收,騎機車到公館捷運站等摸摸。摸摸好準時,果然在約定的時間出現。中途到台大水源校區7-11補充食物,接著過永福橋,直行到快速道路,接台3線,台7乙。
  • 0718 滿月圓森林遊樂區,非常好,超過七點只好讓政府剝一層皮。雖然之前地圖課從北插天山登山口走回滿月圓售票亭,但今天老是找不到上去的路,登山口消失了。

    我們傻傻走到滿月圓瀑布,奇怪,這不是上次走北插天山的登山口嗎?這回可沒有阿來教官陪同。計畫趕不上變化,因為樂佩、多崖稜線就在前方,只要往前上稜就可以了。我們硬著頭皮往上爬,到叉路口,阿來教官上次帶我們走左邊陡上路線,可至滿月圓山,取右腰繞(沒有指標),一路上發現非常新的砍痕,雖然路徑小了點,布條舊了點,但我相信一定可以上稜。
  • 0850 乾溪溝休息,那邊有大塊石頭可以坐,趕緊補充一下舒跑,專心面對未知的山路。只要仔細看路跡,想像前人開路邏輯,其實路就在眼前。不久後便進入杉林地。
  • 0940 休息。今天天氣很好,透空處很亮,可是因為地形緩陡不一,常常被透空處欺騙,以為已經上稜了,其實只是平緩地。走幾分鐘後,才看到真正的稜線,相當高。
  • 1040 小樂佩鞍部,當然也是「樂佩、多崖稜線」。上稜有很多種方法,從鞍部上去算蠻聰明的爬山方式。想當初下翠池也是從最低鞍部開始下。用午餐,因為早餐吃的晚,所以胃口不太好,只吃饅頭跟摸摸的水果。山毛櫸是我們的洋傘,枯葉是我們的地布。此外,山毛櫸尚未變色,想看紅色山毛櫸的朋友,得先等一等了。
  • 1140 GO。根據方向判定,上稜後右為多崖山,左為樂佩山,取右。稜線有數不完的假山頭,前一分鐘奮力爬上岩石,後一分鐘抓樹陡下。有時林相茂密,得偏一點繞過「正稜線」。但我始終曉得,當山友說:「加油!快到了!」那表示十分鐘後,還有一個十分鐘。途中經過兩個往滿月圓方向的叉路口,不知哪個可接至豪華獵寮。
  • 1300 ▲多崖山(H1700M)。
    摸摸幫我照的。小休十分鐘,繼續往北插天山推進。我們依然走稜線路,途中碰到幾近垂直陡降地形,奇怪,什麼時候有這個地形?後來仔細想想,上次教授就在這兒幫助學員確保安全。
  • 1400 ▲北插天山(H1727M)。沒人。
    晃了一下還是沒人,奇怪,天氣那麼好,山頂居然沒有人。好吧,空位很多那就大休吧。山頂的水梨蠻好吃的,約莫 1420,終於看到第一組人馬,夫妻檔,他們打赤腳從小烏來爬到北插天山,相當勇敢。

    他們人很好,一直提醒我們提早下山,可是摸黑也是一種訓練,裝備齊全(包括心理狀態),就不用害怕摸黑,反正我們已經打算要摸黑,如果因為怕摸黑而加快腳步,反而容易造成意外。晚上的山也很漂亮呀。
  • 1430 GO。這次改走傳統路線。傳統路線真的快毀了,處處泥水坑,岩石十分光滑,很不好走。走約半小時路程,碰到隱藏人物,他先跟我們兩個握手,然後問我們:「你們知道我是誰嗎?」摸摸好像不知道,我害羞的回答:「北插之怪」,北插之怪笑的好開心,我相信他不會見怪吧。

    我們跟他說還有十多人爬北插天山,他就繼續往上走,看他們有沒有需要幫忙的。
  • 1520 木屋遺址。雖然快天黑了,不過我們決定大休,泡茶享受悠閒的時光。水才剛燒完,又看到「北插之怪」,走超快的。他問我們有沒有頭燈?順道提醒我們水源地可以煮水。因為我們都有頭燈,背的水也夠多,所以才在木屋遺址休息,避開人潮。他認為我們狀況不錯,便一溜煙的飄下山。北插之怪真的是好人。然後我們看到赤腳爬山的夫妻檔,他們繼續往小烏來方向下山。
  • 1600 GO。繼續走傳統路線回滿月圓。途中經過水源地,人依然很多。
  • 1700 東滿步道。這原本是早上的登山口 (殘念)。途中看到一對夫妻準備走回東眼山森林遊樂區牽車。她們的手電筒壞了,可惜我們沒有多的燈具,只好互相提醒對方小心走路。
  • 1730 天色越來越黑,開頭燈繼續下山。膝蓋有點痠痛,想到三峽的小火鍋,不管怎樣今天一定要吃到。在東滿步道刁山還蠻丟臉的。樹林偶有螢火蟲,快到滿月圓廁所的時候,看到亮亮的燈,想不到那麼晚下山,又看到一對夫妻檔,還好他們離廁所很近,安全無虞。到廁所整理一下,慢慢踢回售票口。
  • 1900 售票口。We are back,結束瘋狂迷航的一天。檢討:請仔細研究登山口。

2011年10月22日 星期六

狹義相對論(四) Lorentz Transformation 應用

這篇討論一些應用,與其說應用,不如說驗證。令 γ = 1/√(1 - v^2/c^2) > 1 (Lorentz factor)。
  • 前面提到的 a light-signal, which is proceeding along the positive axis of x, is transmitted according to the equation x - ct = 0. 對 O' 觀察者來說,x' = γ(c-v)t,但將 t 置換成 t' = γ(1 -v/c)t,又會得到 x' = ct'.
  • 談到縮短的量尺。在 K' 坐標系統的量尺,Δx = 1,對 O 觀察者來說,長度是 1/γ < 1,縮短了。值得注意的是,當 K' 的速度越快 (量尺的速度越快),量尺越短。當 v = c,量尺只剩 0 了。此外,1/γ 也暗示量尺速度不可能超過光速!
  • 談到變長的時間。在 K' 座標系統的時鐘,Δt' = 1。對 O 觀察者來說 Δt = γ > 1,時間變長了。
  • 檢驗 Galilei transformation。當 v 遠小於 c 時,γ 接近 1,Lorentz transformation 退化成 Galilei transformation,沒有矛盾。
  • Theorem of the addition of velocities. 在 K' 座標系統有一個人往 the positive axis of x' 以 w 速度快速移動,傳統 Galilei transformation 告訴我們,在 K 座標系統的觀察者 O 會看到這個人以 W = v + w 速度移動 (v 就是 Lorentz transformation 中 K' 相對於 K 的移動速度)。但若考慮相對論,用 x, t 重寫 x' = wt' (公式是 x' = γ(x-vt), t' = γ(t - v/c^2 x)),可得 x = (v + w)/(1 + vw/c^2)t,也就是 W = (v + w)/(1 + vw/c^2).
  • ...

狹義相對論(三) Lorentz Transformation

Standard Configuration:
Consider two observers O and O', each using their own Cartesian coordinate system to measure space and time intervals. O uses K = (t, x, y, z) and O ' uses K' = (t', x', y', z'). Assume further that the coordinate systems are oriented so that the x-axis and the x'-axis are collinear, the y-axis is parallel to the y'-axis, as are the z-axis and the z'-axis. The relative velocity between the two observers is v along the common x-axis. Also assume that the origins of both coordinate systems are the same.

接下來的推導,完全參考 Albert Einstein, Relativity: The Special and General Theory. 1920 的 Appendix I。此外,這邊中英文混用,純粹是懶惰。

對於 O 來說:A light-signal, which is proceeding along the positive axis of x, is transmitted according to the equation
x - ct = 0.
因為「光速不變原理」,對於 O' 來說,則是
x' - ct' = 0.
把 x 想成光束接收器的位置,根據影片「實驗」,measuring-rod 會縮短,因此
(x' - ct') = λ(x - ct).
我們尚未使用「相對性原理」,因此考慮 light rays which are being transmitted along the negative x-axis,應是十分合理的事。因此,
(x' + ct') = μ(x + ct).
解一解令一令,可以得到聯立方程式
x' = ax + bct
ct' = act - bx,
其中 a = (λ + μ)/2, b = (λ - μ)/2. 若觀察者 O' 站在 K' 座標系的原點 (x' = 0),那麼
x = (bc/a) t.
If we call v the velocity with which the origin of K' is moving relative to K, we then have
v = bc/a.
(根據「相對性原理」,the velocity with which the origin of K is moving relative to K' is -v. 因此,假如觀察者 O 站在 (t, x, y, z) 座標系的原點 (x = 0),那麼 t' = at, x' = -bct = (-bc/a) t' = -vt',沒有矛盾,但也解不出 a, b)

(推不下去,慘!因為我們尚未使用「相對性原理」及「time」。)

根據相對性原理,
As judged from K, the length of a unit measuring-rod which is at rest with reference to K' must be exactly the same as the length, as judged from K', of a unit measuring-rod which is at rest relative to K.
當 t = 0 時,
x' = ax, or Δx' = aΔx.
上面意思是 O 看 K' 的 unit measuring-rod,長度是 Δx = 1/a. 此外,當 t' = 0 時,
x' = a(1 - v^2/c^2)x, or Δx' = a(1 - v^2/c^2)Δx.
上面意思是 O' 看 K 的 unit measuring-rod,長度是 Δx' = a(1 - v^2/c^2). 又根據相對性原理,O 與 O' 互看的長度要一樣,也就是說:
1/a = a(1 - v^2/c^2).
接著就是整理數學式子而已,這邊直接略過,狹義相對論首重創新的洞見,數學只是重現愛因斯坦的洞見。於是乎,冰冷的 Lorentz transformation 有了新生命。



回顧一下「我學到的相對論」:
  • Every description of events in space involves the use of a rigid body to which such events have to be referred.
  • If, relative to K, K' is a uniformly moving co-ordinate system devoid of rotation, then natural phenomena run their course with respect to K' according to exactly the same general laws as with respect to K. This statement is called the principle of relativity (in the restricted sense).
  • The velocity of light c (in vacuum) is constant. This statement is called the law of propagation of light.
  • Every reference-body (co-ordinate system) has its own particular time; unless we are told the reference-body to which the statement of time refers, there is no meaning in a statement of the time of an event.
  • Lorentz transformation.

2011年10月21日 星期五

狹義相對論(二) 時間也是相對的

強調一下,我對「狹義相對論」不了解,文章內容僅供個人留念,還請各位前輩指點一二。

愛因斯坦認為,時間不能夠被絕對定義,而且時間和信號的速度之間,具有不可分的關係。這是簡單的洞見,也是激進的洞見。底下影片裡的「實驗」值得研究,此外,影片也帶出 spacetime 的概念。


多麼偉大的洞見!好,只要能說清楚講明白,就能設計「真正的實驗」,證明狹義相對論是對的。關於「說清楚講明白」,最好的工具就是「數學」。雖然我們知道答案是 Lorentz transformation,但我們要假裝不知道,單憑影片裡的「實驗」來推導答案。這是我的理想。

2011年10月20日 星期四

狹義相對論(一) 愛因斯坦的問題

路有多遠,就走多遠,或許我可以再瞭解「狹義相對論」多一點吧。

雖然「曾」想好好念狹義相對論,但卻不得其門而入,頗為遺憾。但最近買一本不錯的書,「愛因斯坦,他的人生、他的宇宙」,讓我再度燃起熱情,說不定真能讓我一窺狹義相對論的奧妙吧?!
伽利略指出,所有運動與力學法則 (那時電磁法則尚未發現) 在等速參考座標中都相同。
也請參考這則影片,清楚闡釋伽利略物理觀:


愛因斯坦也認同「相對性原理」,但愛因斯坦想一個問題:
「想像騎在一道光束旁邊,那麼光的行為表現也是相同情況嗎?」
這是怎麼一回事?自物理學家發現電磁法則後,愛因斯坦感覺整個發展「非常令人鬱悶」。以下影片前半段描述這個悖論:

後半段描述「光速不變原理」帶來的新衝擊:時間會變慢 (time dilation)。影片做的真好,一口氣破除我很多疑惑。回到上面問題,該怎麼合理解釋呢?時間!