Van der Waals equation - Newton's method

10 次查看(过去 30 天)
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 中查找有关 App Building 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by