the code doesn't update the values

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

 採用された回答

dpb
dpb 2014 年 5 月 1 日
編集済み: dpb 2014 年 5 月 2 日

0 投票

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.

4 件のコメント

ibrahim
ibrahim 2014 年 5 月 2 日
i started with t=300
dpb
dpb 2014 年 5 月 2 日
編集済み: dpb 2014 年 5 月 2 日
Your equations are very unstable--in particular t oscillates wildly and then essentially "blows up". Observe first few iterations...
>> t=300;p=0;
>> n=1; disp([n t p])
while n<6
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;
disp([n t p])
end
1 300 0
2.0000 355.3940 3.5308
3.0000 -360.1268 51.8135
1.0e+18 *
0.0000 -3.4568 + 2.5115i 0.2333 - 0.1695i
5.0000 407.7179 0
1.0e+03 *
0.0060 -4.1697 0.3089
>>
This isn't a Matlab problem; it's in the equations as written...
ibrahim
ibrahim 2014 年 5 月 3 日
thank you
dpb
dpb 2014 年 5 月 3 日
So what are the equations intended to represent and where did you obtain them? Looks like a correlation of some sort; are you sure you've coded them correctly and are using proper units to scale t,p initial values within defined range of the correlation is so?

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 1 日

0 投票

You need to initialize your variable t

カテゴリ

ヘルプ センター および File ExchangeFunction Creation についてさらに検索

質問済み:

2014 年 5 月 1 日

コメント済み:

dpb
2014 年 5 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by