MATLAB: The code doesn’t update the values

fixed-point iteration

anyone can help with this matlab code it doesn't update the values of p and t
n=1
while n<20
p=10^((30.59051-8.2*log10(t))+(0.0024804*t)-(3142.31/t))
t=314+((6.324-p)/(6.66*(10^-4)*101.32));
n=n+1;
end

Best Answer

Of course it does, it just doesn't do what you think it should, apparently...
ADDENDUM-
If you're also expecting to build vectors of t and p, then you need to tell Matlab that, too...
Several problems here...
  • First, t is undefined at the beginning of the loop
What is it to be to begin with. If you start w/ t=0, then
log10(0)-->-Inf
and you divide by it later on, too. Solve those issues and you'll at least get some numeric output.
Before the loop add
p=zeros(20,1); t=p; % preallocate
Inside the loop then
p=...
needs must become
p(n)=...;
and likewise for t to save the individual values.
Related Question