Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Why is this wrong??

2 ビュー (過去 30 日間)
Iris
Iris 2012 年 10 月 24 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello :) I'm trying to draw the plots for E=a*c when j = 1 and E = a*b when j assumes other values, all in the same figure. The program just draws the first one, for E=a*c, and I cant understand why because it computes all different E for all the j (computes but does not do the plot). Can you tell me what I'm doing wrong? Your help will be very appreciated! Thanks in advance!
hold on
for j = 1:i
tau = (12*v*t(j)*Myr)/ro^2;
I = besseli(0.25,2*x./tau);
a = (md/(2*pi*ro));
b = (tau^-1).*(x.^-1/4).*I.*exp(-(1+x.^2)/tau);
c = normpdf(x,1,0.05);
if j == 1
E = a.*c;
else
E = a.*b
end
plot(x, E.*(1/a), colors(j))
end
hold off
  3 件のコメント
Iris
Iris 2012 年 10 月 24 日
Ms = 1.98919e33;
Rs = 6.9599e10;
Myr = 3.15569e13;
v = 1e5;
md = 0.01*Ms;
ro = 2*Rs;
x = [0:0.016:16]
t = [0:2e12:1e13];
i = length(t);
colors = ['r' 'b' 'g' 'b' 'g' 'b' ];
for j = 1:i
tau = (12*v*t(j)*Myr)/ro^2;
I = besseli(0.25,2*x./tau);
a = (md/(2*pi*ro));
b = (tau^-1).*(x.^-1/4).*I.*exp(-(1+x.^2)/tau);
c = normpdf(x,1,0.05);
if j == 1
E = a.*c;
else
E = a.*b
end
hold on
plot(x, E.*(1/a), colors(j))
end
hold off
end
Christoph
Christoph 2012 年 10 月 24 日
Weird since it works for me (R2008a, V7.6.0). Have you checked the output using subplot(2,3,j) at the start of the loop? since the value of E peaks at "8" in the 1st and <10^-12 in the other plots, so all together they appear as line... Otherwise, which Matlab release do you use?

回答 (2 件)

Matt Fig
Matt Fig 2012 年 10 月 24 日
編集済み: Matt Fig 2012 年 10 月 24 日
I run your code and it plots 6 lines. check for yourself:
>> length(findobj('type','line'))
ans =
6
I think maybe you are not noticing because some lines overlap. Have a look:
ylim([0 1e-12])

Matt J
Matt J 2012 年 10 月 24 日
Might be useful to change this
hold on
plot(x, E.*(1/a), colors(j))
to this
semilogy(x, E.*(1/a), colors(j));
hold on

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by