1 / 6

COMP 116: Introduction to Scientific Programming

COMP 116: Introduction to Scientific Programming . Lecture 26: Writing Loops. Vector B=2*A. Write a function that takes as an input a vector A and returns the vector B=2*A. You are allowed to multiply only scalars We have to visit every element of A. We have to compute all elements of B.

badru
Download Presentation

COMP 116: Introduction to Scientific Programming

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. COMP 116: Introduction to Scientific Programming Lecture 26: Writing Loops

  2. Vector B=2*A Write a function that takes as an input a vector A and returns the vector B=2*A. You are allowed to multiply only scalars • We have to visit every element of A. • We have to compute all elements of B. • ith element of A affects only the ith element of B

  3. Matrix B=2*A Write a function that takes as an input matrix A and returns the matrix B=2*A. You are allowed to multiply only scalars • We have to visit every element of A. • We have to compute all elements of B. • (i,j)thelement of A affects only the (i,j)thelement of B

  4. Find the number of vowels in a string • The input is a string str, output is a single number num_vowels • We have to visit every character of str • Each character of str affects num_vowels • i.e. accumulate the effect of each character of str

  5. Break sentence into words • Write a function get_the_words that • Takes as an input a sentence (in the form of a string) e.g. ‘This is a true statement’ • And returns a cell array of the words in the sentence i.e. {‘This’, ‘is’, ‘a’, ‘true’, ‘statement’} • Is there a clear correspondence between the input and output pointers? • What smaller problems would be helpful in solving the above problem?

  6. Continue with structures in Lec 25

More Related