![Page 1: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/1.jpg)
General Computer General Computer Science Science
for Engineersfor EngineersCISC 106CISC 106
Lecture 05Lecture 05
James AtlasComputer and Information Sciences
6/22/2009
![Page 2: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/2.jpg)
Lecture OverviewLecture OverviewReviewPlotting
Simple PlotsArraysRecursion
![Page 3: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/3.jpg)
ReviewFor loopIf statement
![Page 4: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/4.jpg)
Branching ConstructsWe already covered the IF
statement
Why would IF be considered a “branch”?
![Page 5: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/5.jpg)
Branching ConstructsWhy would IF be considered a
“branch”? ◦Let’s look at what happens to our
code when it is executing on the CPU
![Page 6: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/6.jpg)
Switch constructswitch (switch_expression)case case_expr_1 statement 1 statement 2case case_expr_2 statement 1 statement 2otherwise statement 1 statement 2end
![Page 7: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/7.jpg)
Switch constructcolor = ‘yellow’;switch (color)case ‘red’ disp(‘Stop now!’);case ‘green’ disp(‘Proceed through intersection.’);case ‘yellow’ disp(‘Prepare to stop.’);otherwise disp(‘Illegal color encountered.’);end
![Page 8: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/8.jpg)
For loop for sum integers total = 0;
for i = 1:1:100 loop starts at 1 total = total+i; loop increments
by 1 end
![Page 9: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/9.jpg)
While loop
while expression statementend
![Page 10: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/10.jpg)
While loop for sum integers total = 0; i = 1;
while i <= 100 loop starts at 1 total = total+i; loop increments
by 1 i = i + 1;
end
![Page 11: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/11.jpg)
Recursion
![Page 12: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/12.jpg)
PlotPlotUsing the plot command
plot(<array 1>,<array 2>)
where array1 is the x-axis and array2 is the y-axis
NOTE: array1 and array2 must be equal in terms of size of dimensions!
![Page 13: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/13.jpg)
PlotPlotFor example:
x=[1 2 3 4 5];y=[10 20 30 40 50];
plot(x,y)
![Page 14: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/14.jpg)
PlotPlotOther useful command with plotxlabel(‘<string>’) – sets the label for
the x-axisylabel(‘<string>’) – sets the label for
the y-axisgrid on – creates a grid title(‘<string>’) – sets title of the plot
![Page 15: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/15.jpg)
PlotPlotFor example:
x=0:1:10;y=x.^2 - 10.*x + 15;
plot(x,y)
![Page 16: General Computer Science for Engineers CISC 106 Lecture 05](https://reader034.vdocument.in/reader034/viewer/2022051517/56814e80550346895dbc1e34/html5/thumbnails/16.jpg)
Plot commandstitle(‘Graph Title’);xlabel(‘X axis label’);ylabel(‘Y axis label’);grid on;legend(‘series 1’, ‘series 2’, ..., ‘BR’);
print -dpng mygraph.png