※ 引述《wen7774 (文...)》之銘言:
: 我嘗試用fsolve解多元非線性問題
: 第一次寫matlab,參考板上之前的討論
: 原始題目
: (A-x-y)(B-x-β) = K1(x-α)
: (A-x-y)(C-y-α) = K2(y-β)
: (x-α) (C-y-α) = K3(α+β)
: (y-β)(B-x-β) = K4(α+β)
: Constant: K1.K2.K3.K4
: input : A.B.C
: output: α.β.x.y
create a file to put functions:
=========== prac.m =============
function F = prac(x, A, B, C, K)
F = [(A-x(1)-x(2))*(B-x(1)-x(4))-K(1)*(x(1)-x(3));
(A-x(1)-x(2))*(C-x(2)-x(3))-K(2)*(x(2)-x(4));
(x(1)-x(3))*(C-x(2)-x(3))-K(3)*(x(3)+x(4));
(x(2)-x(3))*(B-x(1)-x(4))-K(4)*(x(3)+x(4));];
end
=================================
solve.m:
A=30;B=20;C=60; %input parameter
K1=2;K2=5.71;K3=3;K4=1.0; %constant
x01 = [1,1,1,1];
fsolve(@(x) prac(x,A,B,C, [K1,K2,K3,K4]),x01)
ans =
10.1211 18.1556 8.6104 8.1256
你也可以把prac.m直接用anonymous function取代 隨你