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 Exchange에서 Function 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