Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.34 KB | None | 0 0
  1. %% Declaring constants and importing data
  2.     close all
  3.     clear all
  4.     load randinits
  5.     load randwebs
  6.     n=1;
  7.     SpeciesSurvied = zeros(1000,1);
  8.     DeadCriteria = 0.001;
  9.     NrSpeciesSurvied = zeros(1,11);
  10.     TimeEnd = 5000;
  11.     Edges = 0:11;
  12.     options = odeset ('NonNegative',1:10);
  13.  
  14. %% Assignment 1. Find the solution with the first matrix.
  15.     A = randwebscell{1};
  16.     x = randinitscell{1};
  17.     dx_dt = @(t,x) x.*A*x;
  18.     [t,y]= ode45(@(t,x)dx_dt(t,x),[0 5000],x,options);
  19.     plot(t,y)
  20.  
  21. %% Assignment 2. Examine the solution and determine how many species are alive
  22. SpeciesSurvied = sum(y(end,:) > DeadCriteria);
  23.  
  24. %% Assignment 3. Combine step 1 & 2 for all 1000 sets matrices.
  25. while n<1000
  26. A = randwebscell{n};
  27. x = randinitscell{n};
  28. dx_dt = @(t,x) x.*A*x;
  29. [t,y]= ode45(@(t,x)dx_dt(t,x),[0 TimeEnd],x,options);
  30. SpeciesSurvied(n) = sum(y(end,:) > DeadCriteria);
  31. n=n+1;
  32. end
  33.  
  34. %% Assignment 4.Compute how often 1,2...10 species survived.
  35. [AmountOfSurvivals] = histcounts(SpeciesSurvied,Edges);
  36. %% Assignment 5. Plot an example of all ten species survived.
  37. TenSpeciesSurviedIndex = find(SpeciesSurvied == 10);
  38. A = randwebscell{TenSpeciesSurviedIndex(1)};
  39. x = randinitscell{TenSpeciesSurviedIndex(1)};
  40. dx_dt = @(t,x) x.*A*x;
  41. [t,y]= ode45(@(t,x)dx_dt(t,x),[0 TimeEnd],x,options);
  42. plot(t,y)
  43. xlabel('Time')
  44. ylabel('Species')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement