how to solve a system of Ordinary Differential Equations (ODE's) in Matlab -
i have solve scheme of ordinary differential equations of form:
dx/ds = 1/x * [y* (g + s/y) - a*x*f(x^2,y^2)] dy/ds = 1/x * [-y * (b + y) * f()] - y/s - c
where x, , y variables need find out, , s independent variable; rest constants. i've tried solve ode45 no success far:
y = ode45(@yprime, s, [1 1]); function dyds = yprime(s,y) global g v0 d dyds_1 = 1./y(1) .*(y(2) .* (g + s ./ y(2)) - .* y(1) .* sqrt(y(1).^2 + (v0 + y(2)).^2)); dyds_2 = - (y(2) .* (v0 + y(2)) .* sqrt(y(1).^2 + (v0 + y(2)).^2))./y(1) - y(2)./s - d; dyds = [dyds_1; dyds_2]; homecoming
where @yprime has scheme of equations. next error message:
yprime returns vector of length 0, length of initial conditions vector 2. vector returned yprime , initial conditions vector must have same number of elements.
any ideas? thanks
certainly, should have @ function yprime
. using simple model shares number of differential state variables problem, have @ example.
function dyds = yprime(s, y) dyds = zeros(2, 1); dyds(1) = y(1) + y(2); dyds(2) = 0.5 * y(1); end
yprime
must homecoming column vector holds values of 2 right hand sides. input argument s
can ignored because model time-independent. illustration show hard in not of form dy/dt = f(t, y). have rearrange equations first step. help rename x
y(1)
, y
y(2)
.
also, sure global g v0 d
not empty? if 1 of variables remains uninitialized, multiplying state variables empty matrix, resulting in empty vector dyds
beingness returned. can tested with
assert(~isempty(v0), 'v0 not initialized');
in yprime
, or employ debugging breakpoint.
matlab differential-equations ode
No comments:
Post a Comment