how to change on variable and run a loop again plotting the results

2 次查看(过去 30 天)
i have the following code;
% Lengths of Linkages
a=269.755;
b=182.014;
c=345.91;
d=154.91;
e=110.524;
% Initial Angles
theta0=0.544892;
theta20=2.504722;
theta30=0.612262;
alpha=0.559028959;
% J-Values & Geometry Calculations
j1=d/a;
j2=d/c;
j3=(a^2 - b^2 + c^2 + d^2)/(2*a*c);
j4=d/b;
j5=(c^2 - d^2 - a^2 - b^2)/(2*a*b);
q=atan((a*sin(theta20))/(d-(a*cos(theta20))));
f=sqrt(a^2 +d^2 - 2*a*d*cos(theta20));
p=atan((sqrt(4*b^2*f^2 - (b^2 + f^2 - c^2)^2))/(b^2 +f^2 - c^2));
% Coupler Initial Position
xc=a*cos(theta20) + e*cos(p-q+alpha);
yc=a*sin(theta20) + e*sin(p-q+alpha);
z=-xc*cos(theta0) - yc*sin(theta0);
% Range Of Input Angles
theta2=[(theta20-(degtorad(45))):pi/180:(theta20+(degtorad(45)))];
% Array
camber=[]; height=[];
% Loop
for i=theta2;
D=j5-j1+((1+j4)*cos(i));
E=-2*sin(i);
F=j5+j1-((1-j4)*cos(i));
theta3=2*atan((-E-sqrt(E^2 - 4*D*F))/(2*D));
% Camber Angle
camber(end+1)=radtodeg(theta30-theta3);
q1=atan((a*sin(i))/(d-(a*cos(i))));
f1=sqrt(a^2 +d^2 - 2*a*d*cos(i));
p1=atan((sqrt(4*b^2*f1^2 - (b^2 + f1^2 - c^2)^2))/(b^2 +f1^2 - c^2));
% Coupler Position
xc1=a*cos(i) + e*cos(p-q+alpha);
yc1=a*sin(i) + e*sin(p-q+alpha);
z1=-xc1*cos(theta0) - yc1*sin(theta0);
height(end+1)=z1-z;
end
% Plot Results
figure
plot(camber,height,'linewidth',4)
grid on
xlabel('camber angle(degrees)','FontSize',18)
ylabel('Wheel Travel(mm)','FontSize',18)
title('Camber Angle With Wheel Travel','FontSize',20)
what i want to be able to do is change the variables 'theta20' and 'theta'30' to something slightly above and slightly below the current values and plot them all on the same graph, should be 5 curves in total. i'm not sure if this requires another for loop or not? or is there an easy way to do this? cheers michael
  2 个评论
Andrew Reibold
Andrew Reibold 2013-5-29
编辑:Andrew Reibold 2013-5-29
Please format your code to where we can read it! :)
If you THOUGHT it was formatted and it just came out wrong, try highlighting your code and clicking the "{} Code" button so that it appears correctly. No one can feasibly spend time combing through your post :(
%If you use the code button it helps make your code stick out for us
%and it also retains better format
x = 1;
if x == 1
msgbox('This is what it should look like')
end
Andrew Reibold
Andrew Reibold 2013-5-29
编辑:Andrew Reibold 2013-5-29
I was bored. Change the code in your question to this
% Lengths of Linkages
a=269.755;
b=182.014;
c=345.91;
d=154.91;
e=110.524;
% Initial Angles
theta0=0.544892;
theta20=2.504722;
theta30=0.612262;
alpha=0.559028959;
% J-Values & Geometry Calculations
j1=d/a;
j2=d/c;
j3=(a^2 - b^2 + c^2 + d^2)/(2*a*c);
j4=d/b;
j5=(c^2 - d^2 - a^2 - b^2)/(2*a*b);
q=atan((a*sin(theta20))/(d-(a*cos(theta20))));
f=sqrt(a^2 +d^2 - 2*a*d*cos(theta20));
p=atan((sqrt(4*b^2*f^2 - (b^2 + f^2 - c^2)^2))/(b^2 +f^2 - c^2));
% Coupler Initial Position
xc=a*cos(theta20) + e*cos(p-q+alpha);
yc=a*sin(theta20) + e*sin(p-q+alpha);
z=-xc*cos(theta0) - yc*sin(theta0);
% Range Of Input Angles
theta2=[(theta20-(degtorad(45))):pi/180:(theta20+(degtorad(45)))];
% Array
camber=[];
height=[];
% Loop
for i=theta2;
D=j5-j1+((1+j4)*cos(i));
E=-2*sin(i); F=j5+j1-((1-j4)*cos(i));
theta3=2*atan((-E-sqrt(E^2 - 4*D*F))/(2*D));
% Camber Angle
camber(end+1)=radtodeg(theta30-theta3);
q1=atan((a*sin(i))/(d-(a*cos(i))));
f1=sqrt(a^2 +d^2 - 2*a*d*cos(i));
p1=atan((sqrt(4*b^2*f1^2 - (b^2 + f1^2 - c^2)^2))/(b^2 +f1^2 - c^2));
% Coupler Position
xc1=a*cos(i) + e*cos(p-q+alpha);
yc1=a*sin(i) + e*sin(p-q+alpha);
z1=-xc1*cos(theta0) - yc1*sin(theta0);
height(end+1)=z1-z;
end
% Plot Results
figure
plot(camber,height,'linewidth',4)
grid on
xlabel('camber angle(degrees)','FontSize',18)
ylabel('Wheel Travel(mm)','FontSize',18)
title('Camber Angle With Wheel Travel','FontSize',20)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by