Soundwaves underwater problem not working correctly

1 view (last 30 days)
Hi!
I have a question regarding problem 7 in the attached document.
I have looked at some of the other posts regarding this question and I have a code which is functioning quite well but I am curious about one thing. In the question they state that the value of z(xf) should be 2500 feet. I do get a nice wave function however after 25 nautical miles the value is more like 2170 feet.
This is my code:
function dZ = undervatten(x,Z)
p=[5.8795547370783 14.4873921534832 257.1922990416989]; %values of p(1,2,3)
c=@(z) 4800+p(1)+((p(2))*z/1000)+((p(3))*exp(-z/1000));
c=c(2000);
q0=(c/cosd(7.8));
dZ=zeros(2,1);
dZ(1)=Z(2);
dZ(2)=-q0^2*(((-p(3)/1000)*exp(-Z(1)/1000))+p(2)/1000)/((4800+p(1)+(p(2)*Z(1)/1000)+(p(3)*exp(-Z(1)/1000))^3));
end
The values of p I got by using the method of least squares and I am fairly certain that they are correct, however I could be wrong.
Then in another document I run the following:
clear all, close all, clc
n=7.8
[X,Z]=ode45(@undervatten,[0:6076*25],[2000 tand(n)]);
plot(X(151700:end),Z(151700:end,1),'-r')
So I have plotted just the last feet that this ray is moving until it is picked up by the reciever. But as you can see, I am not getting the value 2500 feet as the assignment states that I should. What have I done wrong with my code?
Thanks in advance.
  2 Comments
Jan
Jan on 8 Nov 2016
Are you sure that your professor agrees with the publication of the PDF? He owns the copy right.
You can assume, that most of the users of this forum are frightend by a 24 pages pdf with Swedish head lines.
The purpose of
c=@(z) 4800+p(1)+((p(2))*z/1000)+((p(3))*exp(-z/1000));
c=c(2000);
is not clear. Why do you create an anonymous function only to overwrite it in the following line?
Alexander Engman
Alexander Engman on 9 Nov 2016
Hi!
Thank you for your answer.
No, I am not sure about this thus I have removed the file.
The purpose of making this an anonymous function is to make sure that I can change this starting value of 2000 feet if I would need to.
I think I have solved my problem but I have another problem.
I have a function which looks like this:
function dZ=undervatten(x,Z)
p=[5.8795547370783 14.4873921534832 257.1922990416989];
c=4800+p(1)+((p(2))*2000/1000)+((p(3))*exp(-2000/1000));
q0=(c/cosd(n));
% Z(1):=avstånd
% Z(2):=vinkel
dZ=zeros(2,1);
dZ(1)=Z(2);
dZ(2)=-q0^2*(((-p(3)/1000)*exp(-Z(1)/1000))+p(2)/1000)/((4800+p(1)+(p(2)*Z(1)/1000)+(p(3)*exp(-Z(1)/1000))^3));
end
Then I want to be able to call this function for different values of n (which is in q0).
iter=1
for n=-10:14
[X,Z]=ode45(@undervatten,[0:3000],[2000 tand(n)]);
[value(tier)=Z(end,1)
iter=iter+1
end;
n represents starting angles, so basically I want to be able to call the function with angles from -10:14 degrees and then save the end value of Z in a vector, to see what values the different starting angles give after a certain distance (x). How can I change my code to be able to call different values of n for each iteration? Also, I want to be able to plot the different paths of each ray.
Thank you!

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!