Unable to correct errors from my MatLab Script and would like to see a script to compare mine to.
Write a MatLab script that simulates a virus spread.
This problem needs the following parts, some of which are nested loops, ie Part 3, 4 and 5 are nested in Part 2’s loop (for or while):
To build the program first to only deal with infection transmission within the town’s neighbors
The person E(i-1), lives to the left, and E(i+1) lives to the right. Each day, for all 1000 townspeople, check first to see if the ith person E(i) is never infected (value E(i)=0), then check their neighbors. If E(i-1) is infected, compute the probability of infection and if it is > 1 then the ith person becomes infected E(i)=1. Check If E(i) =0, and now check whether E(i+1) is infected, compute the probability again, and if the probability is>1 then again E(i)=1.
When i=1 only check the E(i+1) neighbor, and i=1000 only check the E(i-1) neighbor, as they only have 1 neighbor. See “Part” 4 for how to check the probability of infection.
If this works, you should get some neighbor to neighbor transmission which dies off relatively quickly. If you change P from 1.05 (1/20 odds of transmission per day during infection period) to P = 1.2, you should get more sustained infection numbers.
Now, you can add the classes, there are several ways to do this.
Now plot NumInfected(d) versus d the day.
Code:
townspeople = randi([0 14],1,1000); %assigning random infection
value to 100 people.
pr=0;
pl=0;
hold on;
for d=1:25
numberinfected=0;
for i=1:1000
if townspeople(i)>0
townspeople(i)=townspeople(i)+1;%changing infection sttus
numberinfected=numberinfected+1;%changing number of infected
status
end
if townspeople(i)==15
townspeople(i)= -1;
numberinfected=numberinfected-1;
end
if townspeople(i)==0 && i~= 1 && i~=1000
if townspeople(i-1) >0
pl=floor(1.05*rand);
end
if townspeople(i+1) >0
pr=floor(1.05*rand);
end
%pr is probability of infection due to right neighbour.
%pl is probability of infection due to left neighbour.
if pr >= 1 || pl >= 1
townspeople(i)=1;
numberinfected=numberinfected+1;
pr=0;
pl=0;
end
elseif townspeople(i)==0 && i== 1
if townspeople(i+1) >0
pr=floor(1.05*rand);
end
if pr >= 1
townspeople(i)=1;
numberinfected=numberinfected+1;
pr=0;
end
elseif townspeople(i)==0 && i== 1000
if townspeople(i-1) >0
pl=floor(1.05*rand);
end
if pl >= 1
townspeople(i)=1;
numberinfected=numberinfected+1;
pl=0;
end
end
end
plot(d,numberinfected,'*');
%% Plot the number of infected people for every day(***hold must
be on***)
end
Output:
Second Part
townspeople = randi([0 14],1,1000);%assigning random infection
value to 100 people.
%assigning class status
for k=1:1000
class(k)=0;
end
for k=20:20:1000
class(k)=2;
end
for k=40:40:1000
class(k)=1;
end
infclass1=0;
infclass2=0;
pr=0;
pl=0;
hold on
for d=1:25
numberinfected=0;
for i=1:1000
if townspeople(i)>0
if class(i)==1
infclass1=infclass1+1;
elseif class(i)==2
infclass2=infclass2+1;
end
townspeople(i)=townspeople(i)+1;%changing infection sttus
numberinfected=numberinfected+1;%changing number of infected
status
end
if townspeople(i)==15
townspeople(i)= -1;
numberinfected=numberinfected-1;
end
if townspeople(i)==0 && i~= 1 && i~=1000
if townspeople(i-1) >0
pl=floor(1.05*rand);
end
if townspeople(i+1) >0
pr=floor(1.05*rand);
end
%determing class status for infected townpersons(***different varible named class is used***)
%pr is probability of infection due to right neighbour.
%pl is probability of infection due to left neighbour.
%pclass is probability of infection due to Classmates.
if class(i)==1
pclass=floor(1.05*infclass1*rand);
elseif class(i)==2
pclass=floor(1.05*infclass2*rand);
else pclass=0;
end
if pr >= 1 || pl >= 1 || pclass >=1 %checking whether the
probability is more than 1 or not
townspeople(i)=1;
numberinfected=numberinfected+1;
pr=0;
pl=0;
pclass=0;
end
elseif townspeople(i)==0 && i== 1
if townspeople(i+1) >0
pr=floor(1.05*rand);
end
if class(i)==1
pclass=floor(1.05*infclass1*rand);
elseif class(i)==2
pclass=floor(1.05*infclass2*rand);
else pclass=0;
end
if pr >= 1 || pclass >=1 %checking whether the
probability is more than 1 or not
townspeople(i)=1;
numberinfected=numberinfected+1;
pr=0;
end
elseif townspeople(i)==0 && i== 1000
if townspeople(i-1) >0
pl=floor(1.05*rand);
end
if class(i)==1
pclass=floor(1.05*infclass1*rand);
elseif class(i)==2
pclass=floor(1.05*infclass2*rand);
else pclass=0;
end
if pl >= 1 || pclass>1
townspeople(i)=1;
numberinfected=numberinfected+1;
pl=0;
end
end
end
plot(d,numberinfected,'*');
xlabel('Day');
ylabel('Number of Infected persons');
end
Output:
Unable to correct errors from my MatLab Script and would like to see a script to...
I NEED THE CODE FOR PART 2-MATH MODELING CLASS USING MATH LAB in thrve posed elevator problem, your assistant notified you that there are 60 workers operating on each of 5 floors atop the ground floor in your office building - 300 in total. The elevator occupancy is 10 people, and there are 3 elevators in total. In the worst-case scenario in terms of total transition time, on each elevator ride at least one person is getting off at each...
MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts in order to get full credit. Help me out, thank you f LAB SECTION NAME HW6P3 (30 points) following are infinite series representations of the function, un pra i a script file HW6P3 that determines the value of the function from the sum of the series for a given value of x. The program (1 pt) must prompt the user to enter a value...
Hello, i need help with this homework: Code provided: public class DirectedWeightedExampleSlide18 { public static void main(String[] args) { int currentVertex, userChoice; Scanner input = new Scanner(System.in); // create graph using your WeightedGraph based on author's Graph WeightedGraph myGraph = new WeightedGraph(4); // add labels myGraph.setLabel(0,"Spot zero"); myGraph.setLabel(1,"Spot one"); myGraph.setLabel(2,"Spot two"); myGraph.setLabel(3,"Spot three"); // Add each edge (this directed Graph has 5 edges, // so we add 5 edges) myGraph.addEdge(0,2,9); myGraph.addEdge(1,0,7); myGraph.addEdge(2,3,12); myGraph.addEdge(3,0,15); myGraph.addEdge(3,1,6); // let's pretend we are on...
I REALLY need numbers 2 and 3 and 5 by like tomorrow morning. I have no clue how to do these. I know the image quality is iffy but please help as best you can Homework1 STA4322 Homework 1, Spring 2019 Please turn in your own work, though you may discuss the problems with classmates, the TA, the Professor, the internet, etc. The most important thing is that you understand the problems and how they are solved as they will...
Exercise 2. Use R script please Advanced Math use R studio I would like to see a very well documented pdf file with your comments on the steps, and the complete information on your generated sample. Thank you! NOTE for R users: Please export your generated sample as a .csv file (or Rdata file if you prefer). You can find some useful info here. Exercise 2 (20pt). Generate a random sample of size 25 from a normal distribution with mean...
Problem 3 (13 pts): (modified from Attaway Problem 3.39) a) (5 pts) Using the Matlab rand () function, create a script that generates a row vector (1 row X 20 columns) of random numbers, each with magnitude between 0 and 5 b) (3 pts) Use the round() function to turn all of the values into whole numbers by rounding down (truncate the decimal part on your vector) c) (5 pts) Add code to your script to generate a new vector...
Programming in java In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...
I would just like to check my work on this. Using bioinformatics. 1. a) Find Accession NG_016141.1. what is the name of this sequence and on what chromosome is it located? b) The e-value represents the probability that the sequence you are testing does NOT match the sequence in the database. Let’s say you have a sequence from humans that did not have a known function. It matches to the GFP sequence from jellyfish with an e-value of 1e-2 and...
During lab 4, we have seen numerical implementation of Fourier Series for periodic signals. As first part of this assignment, you need to write a Matlab function that would take an array representing a single period of a signal (x), corresponding time array (t), and return the Fourier Series coefficients (Ck) in exponential form. The function should also be able to take two (2) optional input arguments: number of Fourier coefficients (Nk) and plot option (p). Use the template ‘fourier_series_exp.m’...