I'm studying numerical analysis and the answer for this problem (the question is in English) that is solved with the following code:
p1 = -20.2090;
p2 = 17.3368;
p3 = 272.9057;
beta = 7.8*pi/180;
x0 = 2000;
c = @(z)4800+p1+p2*z(1)/1000+p3*exp(-.75*z(1)/1000);
cp = @(z)(p2/1000-.75/1000*p3*exp(-.75*z(1)/1000));
q0 = (c(x0)/cos(beta))^2;
ode = @(t,z)[z(2); -q0*cp(z)/c(z).^3];
IC = [x0; tan(beta)];
[x,z] = ode45(ode,[0 25*6076], IC);
plot(x,z(:,1))
But I don't understand the strategy of the above code. I could think that a second-degree differential equation should be solved using a transformation from second degree to a system of first-degree equation but it doesn't look like that is done. I do understand how we get the coefficients p1, p2, p3, beta and x0, that the c=... is the speed of sound related to depth and cp=... is the derivative. I would like to know what happens next and why the code solves the equation when it doesn't do a transformation. What is the purpose and meaning of z(2)in the ode and why does the ode look like is does? I know that ; in matlab means a second row and that z(2) means the second element in z, but why are those uder and how does it contribute to the correct answer?
Please help me understand.
odeis the system matrix? Thank you for the comments and explanations. I think that I understand what the code does. It seems that ode45 is time-stepping with out system matrix and initial condition as arguments to ode45. Please correct me if I'm mistaken. – Niklas Rosencrantz Sep 16 '15 at 18:45