The background is that I'm solving a problem in numerical analysis and I seem to be halfway having solved the non-linear system and now getting to the part where I should apply solving differential equation.
The code so far is
z=[0:500:4000 5000:1000:12000]; 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]; 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-');
And the system of equations is stated in the math question. Now I suppose that I should define a function something like
function f=fsys(x, z) f= ...
But first I suppose that I must rewrite the system from second order to first order which is just math theory, right? So I first rewrite the system to first order and then I define the function in matlab and finally something like
xend=...; z0=... [X,Z]=ode45(@fsys,[0, xend],z0); zs=Z(end), plot(X,Z,'--')
Can you help me define fsys, tell me how to proceed, confirm or reject that I'm on the right way? Any hints if you don't want to help me but hint at how to learn matlab well enough to solve this "pretty simple math"?
I think I can transform the system in the usual way:
u = z' u' = z''
The system becomes
Since z is a function of x, u and u' are also functions of x and thus this system till become a first-ordet system but how do I program the solution in matlab? How do I use that u=tan(b0)?