Troubles with ode45 solving two ODEs?
I am solving two the first order ODEs:
$$p_0 p_0'=-\dfrac{32 \beta}{R^4}$$
$$(p_0p_1)'=-\dfrac{2-\sigma_v}{\sigma_v}\dfrac{8}{R}p_0'$$
I wrote following matlab code for solving it with ode45
function f= odefun_moja(Z,P) P=zeros(2,1) p0=P(1); p1=P(2); beta=1; R=2; sig=1; %%% EQUATIONS!!! dp0dz=-32*beta/(p0*R^4); dp1dz=(-((2-sig)/sig)*8*dp0dz/R-dp0dz*p1)/p0; %%% EQUATIONS!!! f=[dpodz; dp1dz];
But after run with
function main_moja z0=0; zf=100; zspan=[z0,zf]; y0=[1 0; 1 0]; options = odeset('RelTol', 10.0^(-7), 'AbsTol' , 10.0^(-7)); [Z,P]=ode45(@odeset_moja,zspan,y0,options);
I got his message:
> Error using odearguments (line 92) ODEFUN_MOJA returns a vector of > length 1, but the length of initial conditions vector is 4. The vector > returned by ODEFUN_MOJA and the initial conditions vector must have > the same number of elements.
When I try to solve first only the first equation, with code:
function f= odefun_moja(Z,P) P=zeros(1,1) p0=P(1); beta=1; R=2; sig=1; %%% EQUATIONS!!! dp0dz=-32*beta/(p0*R^4); %%% EQUATIONS!!! f=[dp0dz];
Error message is this:
Error using feval Error: File: odefun_moja.m Line: 15 Column: 1 Function definitions are not permitted in this context.
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
My questions:
1. Is that good approach for solving this system, start with the first equation, solve it for p0, and after that try to solve second equation? Or use both equations in code would be better?
2. I have next conditions $p_0|_{z=0}=p_{0i}$ and $p_0|_{z=1}=1$. According to literature it is necessary to find $p_0'|_{z=0}$ with shooting method, according to already mentioned $p_0|_{z=1}=1$. *How to connect this two conditions* and shoot $p_0'|_{z=0}$ for already known $p_0|_{z=1}=1$? *Is that condition necessary*, because this is first order equation, is there only one initial condition enough? (It will be the same process for second equation and $p_1$.)
0 Kommentare
Akzeptierte Antwort
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!