Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Declaring constants and importing data
- close all
- clear all
- load randinits
- load randwebs
- n=1;
- SpeciesSurvied = zeros(1000,1);
- DeadCriteria = 0.001;
- NrSpeciesSurvied = zeros(1,11);
- TimeEnd = 5000;
- Edges = 0:11;
- options = odeset ('NonNegative',1:10);
- %% Assignment 1. Find the solution with the first matrix.
- A = randwebscell{1};
- x = randinitscell{1};
- dx_dt = @(t,x) x.*A*x;
- [t,y]= ode45(@(t,x)dx_dt(t,x),[0 5000],x,options);
- plot(t,y)
- %% Assignment 2. Examine the solution and determine how many species are alive
- SpeciesSurvied = sum(y(end,:) > DeadCriteria);
- %% Assignment 3. Combine step 1 & 2 for all 1000 sets matrices.
- while n<1000
- A = randwebscell{n};
- x = randinitscell{n};
- dx_dt = @(t,x) x.*A*x;
- [t,y]= ode45(@(t,x)dx_dt(t,x),[0 TimeEnd],x,options);
- SpeciesSurvied(n) = sum(y(end,:) > DeadCriteria);
- n=n+1;
- end
- %% Assignment 4.Compute how often 1,2...10 species survived.
- [AmountOfSurvivals] = histcounts(SpeciesSurvied,Edges);
- %% Assignment 5. Plot an example of all ten species survived.
- TenSpeciesSurviedIndex = find(SpeciesSurvied == 10);
- A = randwebscell{TenSpeciesSurviedIndex(1)};
- x = randinitscell{TenSpeciesSurviedIndex(1)};
- dx_dt = @(t,x) x.*A*x;
- [t,y]= ode45(@(t,x)dx_dt(t,x),[0 TimeEnd],x,options);
- plot(t,y)
- xlabel('Time')
- ylabel('Species')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement