14、MATLAB编程:条件语句、循环结构与实际应用

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值