MATLAB编程:条件语句、循环结构与实际应用
1. 关系与逻辑运算符解决问题
在解决问题时,使用关系和逻辑运算符的关键在于利用 find 命令来确定逻辑表达式 (h >= 6) & (v <= 16) 为真的时间。以下是具体步骤:
1. 生成向量 :生成对应时间的向量 h 和 v ,时间间隔要足够小以保证精度,这里选择 thit/100 的间隔,可得到101个时间值。
2. 编写代码 :
% Set the values for initial speed, gravity, and angle.
v0 = 20; g = 9.81; A = 40*pi/180;
% Compute the time to hit.
t_hit = 2*v0*sin(A)/g;
% Compute the arrays containing time, height, and speed.
t = 0:t_hit/100:t_hit;
h = v0*t*sin(A) - 0.5*g*t.^2;
v = sqrt(v0^2 - 2*v0*g*sin(A)*t + g^2*t.^2);
% Determine when the height is no less than 6
% and the speed is no greater than 16.
u = find(h >= 6 &a
超级会员免费看
订阅专栏 解锁全文
181

被折叠的 条评论
为什么被折叠?



