Van der Waals equation - Newton's method

14 ビュー (過去 30 日間)
Blanca Mir Pou
Blanca Mir Pou 2020 年 3 月 24 日
コメント済み: Blanca Mir Pou 2020 年 3 月 25 日
Hi
I'm stuck and I keep getting this error
Not enough input arguments.
Error in fun (line 4)
F(1) = log((3*x - 1)/(3*y - 1)) + 9/(4*T) * (1/x - 1/y) - 1/(3*x - 1) + 1/(3*y - 1);
Error in newton_ndim (line 6)
resd = [norm(feval(F,xk))];
Error in practica5 (line 16)
[XK,resd,n]=newton_ndim(@fun,X,tol,itmax);
Here is my main script
X = [1.2 ; 0.8];
Vk = [];
tol = 1e-16;
itmax = 100;
for T = 0.99:-0.01:0.85
[XK,resd,n]=newton_ndim(@fun,X,tol,itmax);
Vk=[Vk XK(:,end)];
X = XK(:,end);
end
The function I'm trying to solve is this one, obtained from Van der Waals equation
function F = fun (X,T)
x = X(1); y = X(2);
F(1) = log((3*x - 1)/(3*y - 1)) + 9/(4*T) * (1/x - 1/y) - 1/(3*x - 1) + 1/(3*y - 1);
F(2) = (8*T)/3 * (1/(3*x-1) - 1/(3*y-1)) - 1/x^2 + 1/y^2;
end
Do you know how to solve this?

採用された回答

Are Mjaavatten
Are Mjaavatten 2020 年 3 月 25 日
In your code, newton_ndim does not know the value of T and so cannot call fun(X,T). You can probably fix this by defining an inline function (here called ffun) inside your loop:
for T = 0.99:-0.01:0.85
ffun = @(X) fun(X,T);
[XK,resd,n]=newton_ndim(ffun,X,tol,itmax);
Vk=[Vk XK(:,end)];
X = XK(:,end);
end
  1 件のコメント
Blanca Mir Pou
Blanca Mir Pou 2020 年 3 月 25 日
Thank you, it works

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by