How can I finish this difficult assignment?

1 view (last 30 days)
I was assigned this work that I found rather difficult. Now I get error messages after having seemed to solve half the assignment. The assignment is "sound waves under the water" on page 16
I have 3 matlab scripts to solve the problem, first I make a non.linear approximation that I think is correct.
z=[0:500:4000 5000:1000:12000]; % step is 500 in the beginning and then step is 1000
data=[5050 4980 4930 4890 4870 4865 4860 4860 4865 4875 4885 4905 4920 4935 4950 4970 4990];
fun=@(p)(4800 + p(1))*ones(size(z)) +p(2)/1000*z+p(3)*exp(p(4)/1000*z)-data;
x0=[0 0 0 -1]; % Guess
opt = optimset('MaxFunEvals',1000);
p=lsqnonlin(fun,x0,[],[],opt);
fitf=@(t)(4800 + p(1))*ones(size(t)) + p(2)/1000*t+ p(3)*exp(p(4)/1000*t);
tt=linspace(0,12000,1000);
plot(z,data,'r-',tt,fitf(tt),'b-');
p;
Having run the above code the plot with the approximation looks ok. Then my problem arises when trying to solve the differential equation. I have this program
function dZ=sys(x,Z)
c=@(z)4800 + 5.66 + (14.58)*z/1000+ (257.4)*exp(-z/1000); % c(z)
c=c(2000);
% Z(1):=z
% Z(2):=u
dZ=zeros(2,1); % a column vector
dZ(1)=Z(2);
dZ(2)=(c/cosd(7.8))^2*((1287*exp(Z(1)/1000))/5000 + 729/50000)/...
(4800 + 5.66 + (14.58)*Z(1)/1000+ (257.4)*exp(-Z(1)/1000))^3;
end
Then I can call the above program from another script
hold on
x=0:0.5:7000;
for i=-10:14
%i=-10;
[X,Z]=ode45(@sys,x,[2000 tand(i)]);
plot(X,Z(:,1),'r',X,Z(:,2),'b')
i=i+1;
end
hold off
I get error message and I'm not sure if I understood it correctly how to solve the assignment. Could you tell me what should be done?
Warning: Failure at t=4.036432e+03. Unable to meet integration tolerances
without reducing the step size below the smallest value allowed
(7.275958e-12) at time t.
> In ode45 at 309
  1 Comment
Star Strider
Star Strider on 17 Feb 2015
The warning most likely means that you have a discontinuity there. (I didn’t run your code.) Plot what you have to see what it is doing.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!