我正在尝试解决此链接中描述的声音范围问题:
http://en.wikipedia.org/wiki/Sound_ranging#cite_note-old-5
我有一个像这样的Matlab函数:
function [f]=equation1(x)
c = 330 ;%speed of sound meters per second
% unknown variable :
% r1 => x(1)
% theta => x(2)
time2 = 0.455; % Microphone 1 to Microphone 2 time delay
time3 = 0.606; % Microphone 1 to Microphone 3 time delay
% gives :
r2 = 150 %time2*c;
r3 = 200 %time3*c;
r4 = 1267.9; % Distance from Microphone 2 to Microphone 3
r5 = 499.1; % Distance from Microphone 1 to Microphone 3
phi = 16.177; % Angle between Microphone 1 and Microphone 2 measured from Microphone 3
f(1)= -(x(1) + r2)^2 + (x(1)+r3)^2 +r4^2 -2*(x(1)+r3)*r4*cosd(x(2));
f(2)= - x(1)^2 + (x(1)+r3)^2 + r5^2 - 2*(x(1)+r3)*r5*cosd(x(2)-phi);
end
当我运行[x,feval]=fsolve(@equation1,[100 10])
时,代码会返回结果x= 581.4332 -31.8492
。但在示例中r1
是1621米。我在这个程序中没有看到我的错误。
答案 0 :(得分:2)
您交换了r4
和r5
的值,它应该是:
r4 = 499.1; % Distance from Microphone 2 to Microphone 3
r5 = 1267.9; % Distance from Microphone 1 to Microphone 3
此外,控制台返回的输出值为feval
,而不是x
。使用r4
和r5
的正确值,我会显示正确的答案:
[x,feval]=fsolve(@equation1,[100 10]);
disp(x);
输出
1.0e+03 *
1.6230 0.0764
正如所料。