Van der Waals equation - Newton's method

11 vues (au cours des 30 derniers jours)
Blanca Mir Pou
Blanca Mir Pou le 24 Mar 2020
Commenté : Blanca Mir Pou le 25 Mar 2020
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?

Réponse acceptée

Are Mjaavatten
Are Mjaavatten le 25 Mar 2020
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 commentaire
Blanca Mir Pou
Blanca Mir Pou le 25 Mar 2020
Thank you, it works

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by