Matlab error in ode45 or fourth-order Runge-Kutta method to solve a system of coupled ODEs -


i beginner @ matlab programming , runge-kutta method well.

i'm trying solve system of coupled odes using 4th-order runge-kutta method project work.

here problem...

g = 1.4; g = 1.4; k = 0; z = 0; b = 0.166667;  syms n;  x2 = symfun(sym('x2(n)'),[n]); x1 = symfun(sym('x1(n)'),[n]); x3 = symfun(sym('x3(n)'),[n]); x4 = symfun(sym('x4(n)'),[n]); x5 = symfun(sym('x5(n)'),[n]);  k1 = [x2 * x1 *n *(1 - z * x2)*(x1 - n) - 2 * x3 * n *(1 - z * x2) - x4^2 * x2 *(1 - z * x2)- g *x3 *x2 ]./ [( g * x3 - (x1 - n)^2 * x2 *(1 - z * x2)) * n];    k2 = [x2 * (1 - z * x2)*(x1 * x2 * ( x1 - 2 *n)*( x1 - n) + 2* x3 * n + x4^2 * x2 ) ]./ [( g * x3 - (x1 - n)^2 * x2 *(1 - z * x2)) * n * (x1 - n)]; k3 = [x3 * x2 * (2 * n * x1 - n)^2 * ( 1 - z * x2) + g * x1 * (x1 - 2 *n)* (x1 - n) + x4^2 * g]./ [( g * x3 - (x1 - n)^2 * x2 *(1 - z * x2)) * n * (x1 - n)]; k4 = [x4 * ( x1 + n)] ./ [n * (x1- n)]; k5 = - [x5] ./ [n * (x1- n)];  f = @(n,x) [k1;  k2;  k3;  k4; k5]; [n,xa] = ode45(f,[0 1],[1-b 1/b 1-b 0.01 0.02]); 

errors are

error using odearguments (line 93)
@(n,x)[k1;k2;k3;k4;k5] returns vector of length 1, length
of initial conditions vector 5. vector returned @(n,x)[k1;k2;k3;k4;k5] , initial conditions vector must have
same number of elements.

error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeargs,
odefcn, ...

please guide me how can solve above problem fourth-order runge-kutta method...

the error stems using symbolic functions (mixed function handle) numeric solver. need create numeric functions ode45 function (i replaced of [ , ] ( , ) grouping):

g = 1.4; g = 1.4; k = 0; z = 0; b = 0.166667;  k1 = @(n,x) (x(2) * x(1)*n *(1 - z * x(2))*(x(1) - n) - 2 * x(3) * n *(1 - z * x(2)) - x(4)^2 * x(2) *(1 - z * x(2))- g *x(3) *x(2)) ./ (( g * x(3) - (x(1) - n)^2 * x(2) *(1 - z * x(2))) * n);    k2 = @(n,x) (x(2) * (1 - z * x(2))*(x(1) * x(2) * ( x(1) - 2 *n)*( x(1) - n) + 2* x(3) * n + x(4)^2 * x(2) )) ./ (( g * x(3) - (x(1) - n)^2 * x(2) *(1 - z * x(2))) * n * (x(1) - n)); k3 = @(n,x) (x(3) * x(2) * (2 * n * x(1) - n)^2 * ( 1 - z * x(2)) + g * x(1) * (x(1) - 2 *n)* (x(1) - n) + x(4)^2 * g)./ (( g * x(3) - (x(1) - n)^2 * x(2) *(1 - z * x(2))) * n * (x(1) - n)); k4 = @(n,x) (x(4) * (x(1) + n)) ./ (n * (x(1)- n)); k5 = @(n,x) - x(5) ./ (n * (x(1)- n));  f = @(n,x) [k1(n,x);  k2(n,x);  k3(n,x);  k4(n,x); k5(n,x)]; [n,xa] = ode45(f,[0 1],[1-b 1/b 1-b 0.01 0.02]); 

this runs install of matlab.

however, output nans since function produce infs; may have introduced errors replacing brackets, don't know actual equations i'm going leave you. :)


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -