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 个评论

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?
I am editing my question
xx and dp2dx 1*101 arrays
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.
What are the minimum and maximum values of your xx and dp2dx arrays? Just do
min(xx)
max(xx)
min(dp2dx)
max(dp2dx)
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
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.
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.
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