it is not plotting

Hi,
I try this;
beta1 = 0.4*pi;
alphabar = 1;
dx=0.01;
for i=1:101
xx(i) = (i-1)*dx
end
dt=0.0001;
for nt=1:10001
t=(nt-1)*dt
...
if t==0.1
for i=1:101
t
if xx(i) < t
dp2dx(i) = -beta1-3*beta1^2.*xx(i);
else
dp2dx(i) = -beta1+2.*xx(i)*(-beta1*alphabar-1.5*beta1^2) + ...
t*2*beta1*alphabar;
end
end
figure(16)
plot(xx,dp2dx)
where xx(i) = (i-1)*0.01. But it is not plotting. Any suggestions??

댓글 수: 10

Geoff Hayes
Geoff Hayes 2015년 5월 9일
Meva - what are the dimensions of xx and dp2dx? What is the maximum value of xx? Note how you have a condition
if xx(i) < t
Is this ever satisfied?
Meva
Meva 2015년 5월 9일
I am editing my question
Meva
Meva 2015년 5월 9일
xx and dp2dx 1*101 arrays
Meva
Meva 2015년 5월 9일
yes the condition
if xx(i) < t
is satisfied since xx(i) can take 0<xx(i)<0.1 and time is 0.1 so it is satisfied.
Geoff Hayes
Geoff Hayes 2015년 5월 9일
What are the minimum and maximum values of your xx and dp2dx arrays? Just do
min(xx)
max(xx)
min(dp2dx)
max(dp2dx)
Meva
Meva 2015년 5월 9일
편집: Meva 2015년 5월 9일
min of xx is 0 max of xx is 1 and dp2dx is calculated from xx as can be seen. Also dp2dx both min and max values show
-1.2566
So I assume it does not compute dp2/dx
dpb
dpb 2015년 5월 9일
Doesn't answer the question raised...you're assuming something is happening that may not be. As Geoff, says, "show us".
You say "it is not plotting"; what is happening, specifically?
I note you have
figure(16)
in the script before plot---you sure you're looking at the proper figure or have you got the axes there fixed outside the bounds of the data from a previous iteration or somesuch? We can't know these things from here.
I'd suggest just
figure
plot(...
and see wht happens.
NB: Besides the < test Geoff asks about, you also have the conditional
if t==0.1
containing the whole rest of the code snippet. Relying on floating point exact comparison is risky altho in this case it should work as you have an integer multiple of a delta but in general you can't count on a computed floating point value being identical to the constant to the last significant bit; you really should double-check this is actually happening here as well and write the test as
if abs(t-CONDITION)<3*eps(t)
or somesuch other appropriate for the case relative error value.
Meva
Meva 2015년 5월 9일
편집: Meva 2015년 5월 9일
I see that is why I changed the if condition for
if t==0.1
I changed this with
if nt==1001
which gives t=0.1 so they are same.
I now typed
figure
instead of
figure(16)
The result is, I am still not getting the plot. The error should be in dp2/dx lines
Meva
Meva 2015년 5월 9일
편집: Meva 2015년 5월 9일
I now see the reason of not plotting. It is because dp2dx is 1 dimensional just a value not 1*101 array. But I have used this in a for loop. It is supposed to be 1 *101 array.
Meva
Meva 2015년 5월 9일
I solved the problem. Thanks guys.

답변 (0개)

이 질문은 마감되었습니다.

질문:

2015년 5월 9일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by