Download presentation
Presentation is loading. Please wait.
Published byCora Osborne Modified over 8 years ago
1
CS 121 – Quiz 2 2010 Feb 1 st
2
Question 3 Script Outlines #it is always beneficial to write “restart” at the beginning of your script to clear all variables – restart: #Use a, b, g, d to represent alpha, beta, gamma, and delta, which are constants in the formula – a:=0.04; b:=5E-4; g:= 0.2; d:=5E-5; Cc
3
Question 3 #Initial rabbit and fox population – r0:=5486; f0:=15; #Set a variable “years” to represent the number of years that the model should run, which is also the number of loop – years:=45;
4
Question3 #Write a for loop – for i from 1 to years do #calculate the population in next year next_r := r + floor(r*(a-b*f)); next_f := f – floor(f*(g-d*r)); #update the rabit and fox population r:=next_r; f:=next_f; – end do; #print out the population at the end of loop
5
Question 4 You might see different graphs in question4, but you can solve it the same way. You are given a bunch of functions: – g := (t,c) -> plots[display](plottools[line]([t, 0], [t, t+1], color=c)); – gb := (t,c) -> plots[display](plottools[line]([0,t], [t, t+2], color=c)); – f1 := (t,c) -> plots[display](plottools[disk]([t+1,1], color = c)); – ga := (t,c) -> plots[display](plottools[disk]([t+3,1], color = c)); – s := (a,b) -> plots[display]([a(1,red),b(2,blue)], scaling=constrained); – f := (a,b) ->plots[display]([b(-5,red), a(-3,blue)], scaling=constrained);
6
Question 4 And also a graph
7
Question 4 In order to plot the target graph, you need a red disk and a blue disk first. – #Notice function f1 and ga are perfect to do it. – #Observe where the center of the circle is and the color of the disk – #pass appropriate values to function f1 and ga f1(1,red) ga(2,blue)
8
Question 4 Then we need to display two disks in the same graph – #Notice function s is to combine 3 graph a and b together – #a takes 2 parameter: 1 and red – #b takes 2 parameters: 2 and blue – #those are the values we plugged in f1 and ga – #so a and b can be substituted by f1 and ga Finally we came up with the solution – s(f1,ga)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.