Sharks and Fish � � The �sh are p oin ts with masses mo ving accord� f ishm i ing to Newton�s la ws � F � ma � sub ject to an external force �curren t�� The curren t dep ends on p osition� � Use Euler�s metho d to in tegrate� � Accum ulate the mean�square�v elo cit y of all the �sh � � � � � � � f ish v el ocity i X � � � � f � ish i �� and plot it as a function of time� � Cho ose the time step in the in tegrator �see the mat� dt lab co de for details� small enough to k eep the sim ulation accurate� max j v j el ocity � � i � � f ish i � � � � dt max j accel j er ation � � i � � f ish i � Complete matlab implemen tation in �usr�castle�share�pro j�shortcourse�w ator prob��matlab��sh��m � �� lines long ��� excluding commen ts� graphics�
Sharks and Fish � � As in Problem �� the �sh are p oin ts with masses f ish m mo ving according to Newton�s la ws � F � ma � sub ject to an external force �gra vit y�� � In tegrate using Euler�s metho d as in Problem �� � Accum ulate and plot the mean�square�v elo cit y of all the �sh as in Problem �� � Cho ose the time step in the in tegrator as in Problem dt �� � Complete matlab implemen tation in �usr�castle�share�pro j�shortcourse�w ator prob��matlab��sh��m � �� lines long ��� lines excluding commen ts� graphics�
Sharks and Fish �� ak a Game of Life � Fish o ccup y a d �b y� d p erio dic grid� with at most one �sh p er grid cell� � The rules for deciding whether a �sh o ccupies a cell during the next time step are� �� A new �sh is b orn at a grid cell if it is curren tly empt y and exactly three of its eigh t neigh b oring cells are nonempt y � �� A �sh dies of loneliness if it has � or � neigh b ors� �� A �sh dies of o v ercro wding if it has � or more neigh� b ors� �� Other cell con�gurations are stable� � P arallel execution of these rules are relativ ely simple b ecause the next state is purely a function of � cells at the previous state and do es not dep end on other state c hanges at the same step � Complete matlab implemen tation in �usr�castle�share�pro j�shortcourse�w ator prob��matlab��sh��m � �� line inner lo op
Sharks and Fish � � Fish o ccup y a d �b y� d p erio dic grid� with at most one �sh p er grid cell� � Eac h �sh c ho oses a random direction to mo v e at eac h time step� either Up� Do wn� Left or Righ t� � T o resolv e the con�ict of �sh w an ting to mo v e to the same grid p oin t at the same time� w e �rst mo v e those �sh Righ t that w an t to mo v e righ t� then Up� then Left� and then Do wn� Fish cannot mo v e if a cell is o ccupied� A �sh ma y mo v e at most once during a time step� � Complete matlab implemen tation in �usr�castle�share�pro j�shortcourse�w ator prob��matlab��sh��m � ��� lines of matlab� �� min us graphics and commen ts
Sharks and Fish � � Sharks and Fish o ccup y a d �b y� d grid of ��D o cean� mo v� ing� breeding� eating and dying according to rules� � Sharks and Fish ma y only o ccup y grid p oin ts� and ma y only mo v e at discrete clo c k tic ks� � The square region is �p erio dic�� meaning the righ t and left edges are connected� and the top and b ottom re� gions are connected� � Only one shark or one �sh ma y o ccup y a grid p oin t at one time� � Eac h �sh c ho oses a direction to mo v e at eac h time step� b y computing a v ector as the sum of the follo wing com� p onen ts� and then trying to mo v e up �U�� do wn �D�� left �L� or righ t �R� dep ending on the v ector� � a random v ector �eac h comp onen t indep enden t Normal������ � an external force �curren t� whic h is a function of p osition� and � a �gra vitational repulsion� from all sharks� i�e� a ��distance la w with gra vitational constan t ��sh do not attract or rep el �sh�� F I S H R E P E L � If the age of a �sh exceeds � and it mo v es� it F B R E E D lea v es a new �sh b ehind�
Sharks and Fish � �con t� � Eac h sharks also c ho oses a direction v ector� whic h is a sum of � a random v ector �eac h comp onen t indep enden t Normal������ � an external force �same curren t as for �sh� whic h is a function of p osition� � a �gra vitational attraction� to all �sh� i�e� a ��distance la w with gra vitational constan t �sharks do not attract or rep el S H AR K AT T R AC T sharks�� and � a strong� lo cal attraction to nearb y �sh� equal to times the sum of random�length v ectors E AT N O W p oin ting to an y �sh whic h are immediate U� D� L or R nearest neigh b ors� � Sharks �breed� at random� the same w a y �sh do� with probabilit y�of�breeding constan t � P r ob br eed shar k � If the age of a shark exceeds � and it mo v es� it S B R E E D lea v es a new shark b ehind� � A shark mo ving in to the space o ccupied b y a �sh eats the �sh� � Sharks whic h ha v e not eaten for time steps S T AR V E die�
Sharks and Fish � �con t� Con�ict Resolutio n � If t w o �sh or t w o sharks w an t to mo v e in to the same lo cation in a time step� w e ha v e a con�ict� � T o resolv e the con�ict� w e imp ose a priorit y sc heme� A t eac h time step w e do the follo wing steps sequen tially� � The sharks who w an t to mo v e L get to mo v e� ���� � The sharks who w an t to mo v e R get to mo v e� ���� � The sharks who w an t to mo v e U get to mo v e� ���� � The sharks who w an t to mo v e D get to mo v e� ���� � The �sh who w an t to mo v e L get to mo v e� ���� � The �sh who w an t to mo v e R get to mo v e� ���� � The �sh who w an t to mo v e U get to mo v e� ���� � The �sh who w an t to mo v e D get to mo v e� ���� � It is forbidden to mo v e in to an o ccupied lo cation� ex� cept for sharks mo ving in to lo cations o ccupied b y �sh� and eating them� � Eac h shark or �sh ma y mo v e at most once p er step� � Other� less biased priorit y sc heme are p ossible� suc h as randomization� � Complete matlab implemen tation in �usr�castle�share�pro j�shortcourse�w ator prob��matlab��sh��m
Sharks and Fish � � Sharks and Fish o ccup y a d �b y� d region of ��D o cean� mo ving� breeding� eating and dying according to rules� � The square region is �p erio dic�� meaning the righ t and left edges are connected� and the top and b ottom re� gions are connected� � Fish and Sharks are p erfect disks of radius one� and m ust b e disjoin t� � Eac h �sh has mass and eac h shark mass m � f ishm shar k � Fish mo v e according to Newton�s la ws � F � ma �� under a force whic h is the sum of F � an external force �curren t� whic h is a function of p osition� and � a �gra vitational repulsion� from all sharks� i�e� a ��distance la w with gra vitational constan t ��sh do not attract or rep el �sh�� F I S H R E P E L � Fish colliding with �sh b ounce p erfectly elastically � con� serving kinetic energy and momen tum� � Fish �breed� at random� with the probabilit y of a �sh splitting in to t w o new iden tical �sh during � t� � � equal t � to � for small� The new �sh mo v e with P r ob br eed � � f ish equal and opp osite �relativ e� random v elo cities from the place of birth� Mass� momen tum and energy are not conserv ed�
Recommend
More recommend