Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Infection problem. Use user defined functions at places necessary to write an op

ID: 666193 • Letter: I

Question

Infection problem. Use user defined functions at places necessary to write an optimal code.

Due to a change in the climate, students are prone to infections. They being contagious, spread very easily. For a class of 49 students (7x7 matrix), calculate how infection spreads in a typical day (8 hours). For this create a random matrix using randi() built-in function having values in a range of 0 to 7, 0 meaning sick and contagious, and 7 being healthy. Employ the following conditions to calculate the effect of infection on the class.

a) If the mean of the surrounding values is less than 4, health is reduced by 1. The minimum value that health can attain is 0.

b) If the mean of the surrounding values is greater than 4, health is increased by 1. The maximum value of health that can be attained is 7.

c) If there are two surrounding zeroes, health reduces by 3. If health becomes negative then it becomes 0.

Create a program and run it until 1) all elements are zero 2) None of the elements are zero.

((i need the answer in matlab ))

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

#include<math.h>

int main()

{

int i=0,n=7,sum=0;

float avg;

int mat[7][7];

time_t t;

/* Initializes random number generator */

srand((unsigned) time(&t));

/* Assign value to each student in the group */

for(i=0;i<n;i++)

{

for(i=0;i<n;i++)

{   

mat[i][i]=rand()%8;

}

}

/* For calculating total surrounding value */

for(i=0;i<n;i++)

{

for(i=0;i<n;i++)

{

sum+=mat[i][i];

}

}

avg=sum/49;// mean of surrounding value

floor(avg);// round down value

/*checking each mean value*/

if(avg<4)

{

avg=avg-1;

printf("The health value for 49 students is %d",avg);

}

if(avg >4)

{

avg+=1;

printf("The health value for 49 students is %d",avg);

}

if(avg == 0)

{

avg-=3;

if(avg<0)

avg=0;

printf("The health value for 49 students is %d",avg);

}

return(0);

}