Hi Everyone: How do I correctly compute z? z = 0; for i = 1:7 z = z + v(i) * w(i) end If there are two column vectors v and w, each with 7 elements (i.e., they have dimensions 7x1). Regards, Hal Sent from Surface [[alternative HTML version deleted]]
Dear Hal Are you looking for %*% by any chance? On 26/07/2015 09:38, admin.dslcomputer at gmail.com wrote:> Hi Everyone: > > > How do I correctly compute z? > > > > z = 0; > for i = 1:7 > z = z + v(i) * w(i) > end > > > If there are two column vectors v and w, each with 7 elements (i.e., they have dimensions 7x1). > > > Regards, > > Hal > > > > > > > Sent from Surface > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Michael http://www.dewey.myzen.co.uk/home.html
sum(v*w) There are no "column vectors" in R... there are vectors (that have no "direction"), and there are data frames that might only have one column, and matrices that might have many rows but only one column, and a piece of matrix or data frame is often converted to a vector when indexing is used to extract a column or row (e.g. mat[ , 1 ]). It may feel too dense to absorb at first, but the Introduction to R document that comes with R actually explains all this. Try (re)reading that occasionally until it sinks in. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On July 26, 2015 1:38:24 AM PDT, admin.dslcomputer at gmail.com wrote:>Hi Everyone: > > >How do I correctly compute z? > > > >z = 0; >for i = 1:7 > z = z + v(i) * w(i) >end > > >If there are two column vectors v and w, each with 7 elements (i.e., >they have dimensions 7x1). > > >Regards, > >Hal > > > > > > >Sent from Surface > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
To which I will add: Start up R. At the prompt, type ?Control This will show you the syntax for 'for' loops. (is this homework?) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 7/26/15, 8:19 AM, "R-help on behalf of Jeff Newmiller" <r-help-bounces at r-project.org on behalf of jdnewmil at dcn.davis.ca.us> wrote:>sum(v*w) > >There are no "column vectors" in R... there are vectors (that have no >"direction"), and there are data frames that might only have one column, >and matrices that might have many rows but only one column, and a piece >of matrix or data frame is often converted to a vector when indexing is >used to extract a column or row (e.g. mat[ , 1 ]). > >It may feel too dense to absorb at first, but the Introduction to R >document that comes with R actually explains all this. Try (re)reading >that occasionally until it sinks in. >-------------------------------------------------------------------------- >- >Jeff Newmiller The ..... ..... Go >Live... >DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live >Go... > Live: OO#.. Dead: OO#.. Playing >Research Engineer (Solar/Batteries O.O#. #.O#. with >/Software/Embedded Controllers) .OO#. .OO#. >rocks...1k >-------------------------------------------------------------------------- >- >Sent from my phone. Please excuse my brevity. > >On July 26, 2015 1:38:24 AM PDT, admin.dslcomputer at gmail.com wrote: >>Hi Everyone: >> >> >>How do I correctly compute z? >> >> >> >>z = 0; >>for i = 1:7 >> z = z + v(i) * w(i) >>end >> >> >>If there are two column vectors v and w, each with 7 elements (i.e., >>they have dimensions 7x1). >> >> >>Regards, >> >>Hal >> >> >> >> >> >> >>Sent from Surface >> [[alternative HTML version deleted]] >> >>______________________________________________ >>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide >>http://www.R-project.org/posting-guide.html >>and provide commented, minimal, self-contained, reproducible code. > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.