- Details
- Parent Category: Programming Assignments' Solutions

# We Helped With This MATLAB Programming Homework: Have A Similar One?

Category | Programming |
---|---|

Subject | MATLAB |

Difficulty | College |

Status | Solved |

More Info | Matlab Experts |

## Short Assignment Requirements

## Assignment Code

```
function [S,I,R,N]=DiseaseSimulate(a,b,h,S0,I0,R0,nSteps)
N=zeros(1,nSteps);
S=N;
I=N;
R=N;
for i=1:nSteps
N(i)=S0+I0+R0;
[S(i),I(i),R(i)]=DiseaseStep(a,b,h,S0,I0,R0,N(i));
S0=S(i);
I0=I(i);
R0=R(i);
end
end
```

## Assignment Code

```
function [S ,I, R, N]=DiseaseStep(a,b,h,S0,I0,R0,N)
% Derivative of S
dS=-a.*S0.*I0./N;
% New value of S
S=S0+(h.*dS);
% Derivative of I
dI=(a.*S0.*I0./N)-I0/b;
% New value of I
I=I0+(h.*dI);
% Derivative of R
dR=I0/b;
% R's new value
R=R0+(h*dR);
end
```

## Assignment Code

```
function [isepidemic,maxvalue,maxtime]=IsEpidemic(S0,I0,a,b)
nSteps=1000;
R0=0;
h=0.01;
% Call DiseaseSimulate
[S,I,R,N]=DiseaseSimulate(a,b,h,S0,I0,R0,nSteps);
maxvalue=0;
maxtime=0;
% Check validity of epidemic
if(max(S)-min(S)>0)
fprintf('Is Epidemic')
isepidemic=true;
maxvalue=max(I);
[row,col]=find((I-maxvalue)==0);
maxtime=col*0.01;
fprintf('Is epidemic, time %.2f days, number of people %0.0f
',maxtime,round(maxvalue));
else
isepidemic=false;
end
end
```

## Assignment Code

```
function [ x,y,x1,y1,x2,y2,x3,y3 ] = RotateCircle( R,r,K1,K2,K4,K5 )
% Position of the handle of the small plate
x = cosd(K2)
y = sind(K2)
% Position of bigger plate
x1 = x + cosd(K1)*R
y1 = y + sind(K1)*R
% The limits
K3 = linspace(0,2*pi,360) ;
% The points for the platter
x2 = cos(K3)*R ;
y2 = sin(K3)*R ;
% Teacup points
x3 = cos(K3)+(cosd(K1)*R) ;
y3 = sin(K3)+(sind(K1)*R) ;
% Plot the data on a subplot
subplot(2,3,1) ;
plot(x2,y2,'k') ;
hold on
% Teacup plot
plot(x3,y3,'r') ;
% Handle plot
plot(x1,y1,'Xk') ;
axis equal ;
% Title for the graph
title('Teacup R=6.0 A=0.0 a=3.1') ;
xlabel('Position (meters)') ;
ylabel('Position (meters)') ;
%%
x = cosd(K5)
y = sind(K5)
% Bigger handle while considering the bigger plate's position
x1 = x + cosd(K4)*R
y1 = y + sind(K4)*R
% Create array to make a circle
K3 = linspace(0,2*pi,360) ;
% Platter points
x2 = cos(K3)*R ;
y2 = sin(K3)*R ;
% Points for the teacup
x3 = cos(K3)+(cosd(K4)*R) ;
y3 = sin(K3)+(sind(K4)*R) ;
% Platter plot
subplot(2,3,2) ;
plot(x2,y2,'k') ;
hold on
% Teacup plot
plot(x3,y3,'r') ;
% Handle plot
plot(x1,y1,'Xk') ;
axis equal ;
% Title and labels
title('Teacup R=6.2 A=0.6 a=3.0') ;
xlabel('Position (meters)') ;
ylabel('Position (meters)') ;
end
```