problem with For loop

3 次查看(过去 30 天)
Villanova
Villanova 2012-10-31
Hi, i have written this code, but not sure why I don't get anything in my plot. I was wondering if someone could point out what I doing wrong. I am pretty much trying to plot values for certain v_dot values.
global x1lco x2lco
alpha12 = -2.086211466368665;
alpha22 = 1.378057393962953;
alpha11 = -0.082454051332553;
alpha21 = 0.395565864578256;
alpha0 = 0.641764119934185;
g = (x1lco.^2 + x2lco.^2).^2 + alpha12.*x1lco.^2 + alpha22.*x2lco.^2 + alpha11.*x1lco + alpha21.*x2lco + alpha0;
i = 0
for phi = 0:.01:2*pi;
flag = 0;
i = i + 1;
j = 0;
for r = .01:0.01:3;
j = j + 1;
v_dot = -1.*r.^2.*(g + 2.*(alpha22 - alpha12).*sin(phi).*cos(phi)) -1.*r.*(alpha21.*cos(phi)- alpha11.*sin(phi));
if v_dot >=0 & flag == 0
r_b(i) = r;
phi_b(i) = phi;
flag = 1
end
end
end
x1 = r.*cos(phi);
x2= r.*sin(phi);
plot (x2,x1)

采纳的回答

Kye Taylor
Kye Taylor 2012-10-31
You are only plotting a single point... That is, the variables r and phi are only scalars (1x1 doubles) when you define x1 and x2. Therefore x1 and x2 are also simply scalars.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by