matlab - Stochastic Differential Equations (SDE) in 2 dimensions -


i working on stochastic differential equations first time. looking simulate , solve stochastic differential equations in 2 dimensions.

the model follows:

dp=f(t,p)dt+g(t,p)dw(t)

where:

  • p 2-by-1 vector: p=(theta(t); phi(t))
  • f column vector: f=(sin(theta)+psi* cos(phi); psi* cot(theta)*sin(phi))
  • g 2-by-2 matrix: g=(d 0;0 d/sin(theta))
  • psi parameter , d diffusion constant

i wrote code follows:

function mdl=gyro_2dim(psi,d) % want solve 2-by-1 vector: %p=[theta;phi]; %drift function f=@(t,theta,phi)  [sinth(theta)+psi.*cos(phi)-d.*cot(theta);psi.*cot(theta).*sin(phi)]; %diffusion function g=@(t,theta,phi) [d 0;0 d./sin(theta)]; mdl=sde(f,g) end 

then call function following script:

params.t0   = 0;               % start time of simulation params.tend = 20;              % end time params.dt =0.1;                % time increment d=0.1; nperiods=10; % # of simulated observations psi=1; mdl=gyro_2dim(psi,d); [s,t,z]=simulate(mdl, nperiods,'deltatime',params.dt); plot(t,s) 

when run code, receive error message:

drift rate invalid @ initial conditions or inconsistent model dimensions.

any idea how fix error?

from documentation sde:

user-defined drift-rate function, denoted f. driftrate function returns nvars-by-1 drift-rate vector when called 2 inputs:
- real-valued scalar observation time t.
- nvars-by-1 state vector xt.

a similar specification provided diffusion function. however, you're passing in elements of state vector scalars , have three, rather two, inputs. can try changing model creation function to:

function mdl=gyro_2dim(psi,d) % state vector: p = [theta;phi]; f = @(t,p)[sin(p(1))+psi.*cos(p(2))-d.*cot(p(1));            psi.*cot(p(1)).*sin(p(2))];            % drift g = @(t,p)[d 0;            0 d./sin(p(1))];                       % diffusion mdl = sde(f,g); mdl.starttime = 0;   % set initial time mdl.startstate = ... % set initial conditions 

i changed sinth(theta) sin(p(1)) there no sinth function. can't test don't have financial toolbox (few do).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -