hy,
I am quite new here and I don't have much experience regarding programming and Matlab. But i had an assingment to make a file that calculates the molar volume v.
I tried lots of things and the best code i have till now is the next:
function v=mainfunction(P,T)
global P0
global T0
P0=P;
T0=T;
a=0; b=100;
v0= ((8.31*T)/P);
format long
v=newton('fv','dfv',v0,a,b,10^(10),1000)
end
and this is my secondary function called fv and dfv where I have to use global function:
function y=fv
global P0
global T0
v=((8.31*T0)/P0);
y=(P0+(4.16/(v^2)))*(v0.06)(8.31*T0);
end
and
function y=dfv
global P0
global T0
v=((8.31*T0)/P0);
y= P0  (4.16/(v^2))+((2*4.16*0.05)/(v^3));
end
this secondary functions I have to use in my function called newton, that uses the newton iteration:
function x= newton(fun, dfun,x0,a,b,tol,nmax)
k=0;
while ((k< nmax)&&((abs(fun(x0)))> tol));
x= x0 (feval(fun,x0)/feval(dfun,x0));
k= k+1;
if k > nmax
error(' numbers of iterations above Nmax')
end
if ((x0< (a:b))  (x0>(a:b)));
error('the iteration is outside interval');
end
end
end
I assume my code for the newton iteration is right, but I have trouble using the global function.
Now my question is if anyone could tell where im doing wrong ?
thanks in advance,
ahrid
