Problem with function handle? or something.

조회 수: 2 (최근 30일)
Dakota Burrow
Dakota Burrow 2013년 7월 7일
So, first off, the answer to this problem should be roughly .0028. But, somewhere in the code there is an issue and it will not compute correctly. Can you help?
clc
clear
v = input('Enter initial guess for the volume of methane: ');
R = .518;
pc = 4600;
tc = 191;
T = -40 + 273;
P = 65000;
a = .427*R^2*tc^2.5/pc;
b = .0866*R*tc/pc;
gv =@(v)(R*T)-(((a*(v-b)^2)/(v*(v+b)*sqrt(T))) + P * b)/P;
n = 4;
es = .5*10^(2-n);
[r, I] = Redlich_Kwong(es, v, gv);
fprintf('\nThe calculated volume is : %.6f',r);
fprintf('\nIt took %1.0d iterations to converge.',I);
Function
function [r, I] = Redlich_Kwong(es, v, gv)
I = 0;
ea = 1;
while ea > es
r = gv(v);
ea = 100*abs((r-v)/r);
v = r;
I = I +1;
end
end

채택된 답변

Guru
Guru 2013년 7월 7일
Well, from plotting your input-output behavior of your anonymous function gv(), it converges to about the value of R*T. In other words, for all values of v, gv returns an answer of approximately R*T, so I would guess something is wrong in your equation for gv. As I do not know anything where you came up with gv or what it should be, that's the extent I can be of assistance on this matter. I merely ran a quick monte carlo simulation on a sizeable random distribution of v's from -1000 to +1000 and they all came back around R*T in their results.
HTH

추가 답변 (1개)

Dakota Burrow
Dakota Burrow 2013년 7월 7일
Thank you! R*T was also supposed to be divided by P. Thanks!

카테고리

Help CenterFile Exchange에서 Design of Experiments (DOE)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by