Re: [問題] 解lsqnonlin 最佳化已回收

看板MATLAB作者 (SaltLake)時間16年前 (2009/02/19 10:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《uopy2002 (機掰人)》之銘言: : 整個最主要的目的是有六個未知數在四個方程式中找出最佳的數字 : 主要 : Bx1=1.942127539097260*10^-09; : By1=2.335409989131912*10^-09; : Bz1= 4.326106950381173*10^-10; : x = lsqnonlin (@fun , [0 0 0 1 1 1 Bx1 By1 Bz1 ] ); : 然後在fun.m檔中 : function f =fun(x) : f(1)=3.4485*10^-05*(3*(x(4)*(20-x(1))+x(5)*(20-x(2))+x(6)*(20-x(3)))*(20-x(1))/((20-x(1))^2+(20-x(2))^2+(20-x(3)^2))^(5/2)-x(4)/(((20-x(1))^2+(20-x(2))^2+(20-x(3)))^(3/2)))-x(7); : f(2)=3.4485*10^-05*(3*(x(4)*(20-x(1))+x(5)*(20-x(2))+x(6)*(20-x(3)))*(20-x(2))/((20-x(1))^2+(20-x(2))^2+(20-x(3)^2))^(5/2)-x(5)/(((20-x(1))^2+(20-x(2))^2+(20-x(3)))^(3/2)))-x(8); : f(3)=3.4485*10^-05*(3*(x(4)*(20-x(1))+x(5)*(20-x(2))+x(6)*(20-x(3)))*(20-x(3))/((20-x(1))^2+(20-x(2))^2+(20-x(3)^2))^(5/2)-x(6)/(((20-x(1))^2+(20-x(2))^2+(20-x(3)))^(3/2)))-x(9); : f(4) = x(4)^2+x(5)^2+x(6)^2-1 ; : end : ==================================================== : 問題有幾個 : 1.假設我Bx1 By1 Bz1 就是定值,如何把它傳到fun.m中運算來取代每個式子後面的x(7) x(8) x(9)的值 : 2.我希望它有所限制 [0 0 0 1 1 1 Bx1 By1 Bz1 ]=>我記得這是預測值設定 : 範圍在[0~20 0~20 0~20 0~1 0~1 0~1 Bx1(定值) By1(定值) Bz1(定值) ] 如果堅持要使用 lsqnonlin() 的話 你必須去查優化相關的理論書籍 如果只想簡單用現成工具求解 >> help fmincon FMINCON Finds a constrained minimum of a function of several variables. FMINCON solves problems of the form: min F(X) subject to: A*X <= B, Aeq*X = Beq (linear constraints) X C(X) <= 0, Ceq(X) = 0 (nonlinear constraints) LB <= X <= UB 你想要知道怎樣傳參數也可在那邊查到 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 71.77.1.125
文章代碼(AID): #19dC9Apq (MATLAB)
文章代碼(AID): #19dC9Apq (MATLAB)