Van der Waals equation - Newton's method

조회 수: 3 (최근 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by