I am using Eulers method to calculate positional vectors for 3 animals. Each animal has its own function.
The first animal (mouse) is constrained to a circular path. "xm and ym".
The second animal (cat) uses the first animal coordinates to "chase", these coordinates are "xc and yc".
The last animal (dog) uses the second animal to "chase", "xd and yd".
I have one main script that contains a loop:
However, my confusion arrises when using initial conditions for the cat and dog as inputs to the functions, then writing new " i+1 " values to the arrays of xm, ym, xc and yc.
Cat and dog functions are as follows:
function [xc,yc] = Cat(xm,ym)
dmc = sqrt( (xm-xc)^2 + (ym-yc)^2 );
xc_dot = (vc*(xm-xc))/(dmc);
yc_dot = (vc*(ym-yc))/(dmc);
function [xd,yd] = Dog(xc,yc)
dcd = sqrt( (xc-xd)^2 + (yc-yd)^2 );
xd_dot = (vd*(xc-xd))/(dcd);
yd_dot = (vd*(yc-yd))/(dcd);
Basically my biggest confusion is how to take values of "i" and "i+1" and properly organize them into arrays which are located in the main script file. If the arrays were kept within the Cat and Dog functions, it would be much easier. However they need to be located in the main script. I also thought if I could pass an entire array as an input to the function, however I haven't been able to succesfully do that either
Any help is greatly appreciated.