1 / 16

General Computer Science for Engineers CISC 106 Lecture 05

General Computer Science for Engineers CISC 106 Lecture 05. James Atlas Computer and Information Sciences 6/22/2009. Lecture Overview. Review Plotting Simple Plots Arrays Recursion. Review. For loop If statement. Branching Constructs. We already covered the IF statement

willa
Download Presentation

General Computer Science for Engineers CISC 106 Lecture 05

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. General Computer Science for EngineersCISC 106Lecture 05 James Atlas Computer and Information Sciences 6/22/2009

  2. Lecture Overview • Review • Plotting • Simple Plots • Arrays • Recursion

  3. Review • For loop • If statement

  4. Branching Constructs • We already covered the IF statement • Why would IF be considered a “branch”?

  5. Branching Constructs • Why would IF be considered a “branch”? • Let’s look at what happens to our code when it is executing on the CPU

  6. Switch construct switch (switch_expression) case case_expr_1 statement 1 statement 2 case case_expr_2 statement 1 statement 2 otherwise statement 1 statement 2 end

  7. Switch construct color = ‘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

  8. For loop for sum integers • total = 0; for i = 1:1:100 loop starts at 1 total = total+i; loop increments by 1 end

  9. While loop while expression statement end

  10. 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

  11. Recursion

  12. Plot • Using 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!

  13. Plot • For example: • x=[1 2 3 4 5]; • y=[10 20 30 40 50]; • plot(x,y)

  14. Plot • Other useful command with plot • xlabel(‘<string>’) – sets the label for the x-axis • ylabel(‘<string>’) – sets the label for the y-axis • grid on – creates a grid • title(‘<string>’) – sets title of the plot

  15. Plot • For example: • x=0:1:10; • y=x.^2 - 10.*x + 15; • plot(x,y)

  16. Plot commands • title(‘Graph Title’); • xlabel(‘X axis label’); • ylabel(‘Y axis label’); • grid on; • legend(‘series 1’, ‘series 2’, ..., ‘BR’); • print -dpng mygraph.png

More Related