matlab中用for 循环+条件语句求值:for a=0:.001:15;if(49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)==650);disp(a);end;end;为什么结果总为15.我用笔算大概在12、13左右
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/11 12:01:55
![matlab中用for 循环+条件语句求值:for a=0:.001:15;if(49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)==650);disp(a);end;end;为什么结果总为15.我用笔算大概在12、13左右](/uploads/image/z/1582131-3-1.jpg?t=matlab%E4%B8%AD%E7%94%A8for+%E5%BE%AA%E7%8E%AF%2B%E6%9D%A1%E4%BB%B6%E8%AF%AD%E5%8F%A5%E6%B1%82%E5%80%BC%EF%BC%9Afor+a%3D0%3A.001%3A15%3Bif%2849.82418%2Acos%28a.%2Api.%2F180.%29%2B2768.01.%2Asin%28a.%2Api.%2F180.%29%3D%3D650%29%3Bdisp%28a%29%3Bend%3Bend%3B%E4%B8%BA%E4%BB%80%E4%B9%88%E7%BB%93%E6%9E%9C%E6%80%BB%E4%B8%BA15.%E6%88%91%E7%94%A8%E7%AC%94%E7%AE%97%E5%A4%A7%E6%A6%82%E5%9C%A812%E3%80%8113%E5%B7%A6%E5%8F%B3)
matlab中用for 循环+条件语句求值:for a=0:.001:15;if(49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)==650);disp(a);end;end;为什么结果总为15.我用笔算大概在12、13左右
matlab中用for 循环+条件语句求值:
for a=0:.001:15;
if(49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)==650);disp(a);
end;
end;
为什么结果总为15.我用笔算大概在12、13左右
matlab中用for 循环+条件语句求值:for a=0:.001:15;if(49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)==650);disp(a);end;end;为什么结果总为15.我用笔算大概在12、13左右
你的条件语句中
49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)==650
这个的逻辑值应该永远是假,那么程序肯定相当于
for a=0:.001:15;
if(0);disp(a);
end;
end;
那最后的结果肯定是a=15
那么为什么你的条件的逻辑值是假,显然是计算的截断误差了,所以你应该设置一个阈值theta
49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)==650
这个条件改为:
(49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)>650-theta)&(49.82418*cos(a.*pi./180.)+2768.01.*sin(a.*pi./180.)