Thread Subject: Testing if vector x is twice vector y

Subject: Testing if vector x is twice vector y

From: El Hassan Abdel Fattah

Date: 15 Oct, 2009 18:53:03

Message: 1 of 6

hello all,

im a university student and currently im taking a matlab course this term. i got an assignment due tomorrow and needed some help:

if we have two variables:

x = [4; 1; 4; 6; 2]
y = [3; 9; 2; 3; 1]

question is as follows: Test if all the elements of x are twice as big as the corresponding elements in y OR any element of x is less than the corresponding element of y.

given hint: use the functions 'all( )' and 'any( )' and logic operators ('|', single vertical bar) for vectors.

Thanks for anyones help!!

Hassan

Subject: Testing if vector x is twice vector y

From: Justin

Date: 15 Oct, 2009 19:16:03

Message: 2 of 6

"El Hassan Abdel Fattah" <s8ru9@unb.ca> wrote in message <hb7r2f$8p4$1@fred.mathworks.com>...
> hello all,
>
> im a university student and currently im taking a matlab course this term. i got an assignment due tomorrow and needed some help:
>
> if we have two variables:
>
> x = [4; 1; 4; 6; 2]
> y = [3; 9; 2; 3; 1]
>
> question is as follows: Test if all the elements of x are twice as big as the corresponding elements in y OR any element of x is less than the corresponding element of y.
>
> given hint: use the functions 'all( )' and 'any( )' and logic operators ('|', single vertical bar) for vectors.
>
> Thanks for anyones help!!
>
> Hassan

This can be done in two or 3 commands, but since it's a HW assignment I can't give you an answer and feel honorable. I will give you some hints and you will have to do some reading and thinking.

you might want to use the help command to look up:
1.) the "mod" command
2.) "." based commands (specifically what ./ does)

Good luck.

--Justin

Subject: Testing if vector x is twice vector y

From: us

Date: 15 Oct, 2009 19:17:22

Message: 3 of 6

"El Hassan Abdel Fattah" <s8ru9@unb.ca> wrote in message <hb7r2f$8p4$1@fred.mathworks.com>...
> hello all,
>
> im a university student and currently im taking a matlab course this term. i got an assignment due tomorrow and needed some help:
>
> if we have two variables:
>
> x = [4; 1; 4; 6; 2]
> y = [3; 9; 2; 3; 1]
>
> question is as follows: Test if all the elements of x are twice as big as the corresponding elements in y OR any element of x is less than the corresponding element of y.
>
> given hint: use the functions 'all( )' and 'any( )' and logic operators ('|', single vertical bar) for vectors.
>
> Thanks for anyones help!!
>
> Hassan

a hint:

     help all;
     help any;
     help or;

us

Subject: Testing if vector x is twice vector y

From: El Hassan Abdel Fattah

Date: 15 Oct, 2009 19:46:18

Message: 4 of 6

"Justin " <justink@email.unc.edu> wrote in message <hb7sdj$8a7$1@fred.mathworks.com>...
> "El Hassan Abdel Fattah" <s8ru9@unb.ca> wrote in message <hb7r2f$8p4$1@fred.mathworks.com>...
> > hello all,
> >
> > im a university student and currently im taking a matlab course this term. i got an assignment due tomorrow and needed some help:
> >
> > if we have two variables:
> >
> > x = [4; 1; 4; 6; 2]
> > y = [3; 9; 2; 3; 1]
> >
> > question is as follows: Test if all the elements of x are twice as big as the corresponding elements in y OR any element of x is less than the corresponding element of y.
> >
> > given hint: use the functions 'all( )' and 'any( )' and logic operators ('|', single vertical bar) for vectors.
> >
> > Thanks for anyones help!!
> >
> > Hassan
>
> This can be done in two or 3 commands, but since it's a HW assignment I can't give you an answer and feel honorable. I will give you some hints and you will have to do some reading and thinking.
>
> you might want to use the help command to look up:
> 1.) the "mod" command
> 2.) "." based commands (specifically what ./ does)
>
> Good luck.
>
> --Justin

Thanks for your help. The command i'm writing goes like this: "x=all(y.*2)". I'm basically trying to get matlab to display all elements in x are twice y. my answer comes to be 1, which implies a true statement, however it is false. i know it is very simple but im not getting there for some reason. thanks again

Subject: Testing if vector x is twice vector y

From: dpb

Date: 15 Oct, 2009 20:34:28

Message: 5 of 6

El Hassan Abdel Fattah wrote:
> "Justin " <justink@email.unc.edu> wrote in message <hb7sdj$8a7$1@fred.mathworks.com>...
>> "El Hassan Abdel Fattah" <s8ru9@unb.ca> wrote in message <hb7r2f$8p4$1@fred.mathworks.com>...
>>> hello all,
>>>
>>> im a university student and currently im taking a matlab course this term. i got an assignment due tomorrow and needed some help:
>>>
>>> if we have two variables:
>>>
>>> x = [4; 1; 4; 6; 2]
>>> y = [3; 9; 2; 3; 1]
>>>
>>> question is as follows: Test if all the elements of x are twice
>>> as big as the corresponding elements in y OR any element of x is less than
>>> the corresponding element of y.
>>> given hint: use the functions 'all( )' and 'any( )' and logic
>>> operators ('|', single vertical bar) for vectors.
>>> Thanks for anyones help!!
>>>
>>> Hassan
>> This can be done in two or 3 commands, but since it's a HW
>> assignment I can't give you an answer and feel honorable. I will give you some
>> hints and you will have to do some reading and thinking.
>> you might want to use the help command to look up:
>> 1.) the "mod" command
>> 2.) "." based commands (specifically what ./ does)
>>
...
> Thanks for your help. The command i'm writing goes like this:
> "x=all(y.*2)". I'm basically trying to get matlab to display all
> elements in x are twice y. my answer comes to be 1, which implies a
> true statement, however it is false. i know it is very simple but im
> not getting there for some reason. thanks again

Well, first stop and figure out how you would solve the problem by hand.
  I don't think the above expression would fit into that if you think it
thru that way. IOW, what do you instinctively do in determining whether
your answer is right for the first part, then the second?

I'll make the hint that I don't see mod() coming into play here, at
least the way I'd approach it but agree w/ "./" ... :)

--

Subject: Testing if vector x is twice vector y

From: Steven Lord

Date: 15 Oct, 2009 21:12:40

Message: 6 of 6


"us " <us@neurol.unizh.ch> wrote in message
news:hb7sg2$d7i$1@fred.mathworks.com...
> "El Hassan Abdel Fattah" <s8ru9@unb.ca> wrote in message
> <hb7r2f$8p4$1@fred.mathworks.com>...
>> hello all,
>>
>> im a university student and currently im taking a matlab course this
>> term. i got an assignment due tomorrow and needed some help:
>>
>> if we have two variables:
>>
>> x = [4; 1; 4; 6; 2]
>> y = [3; 9; 2; 3; 1]
>>
>> question is as follows: Test if all the elements of x are twice as big as
>> the corresponding elements in y OR any element of x is less than the
>> corresponding element of y.
>>
>> given hint: use the functions 'all( )' and 'any( )' and logic operators
>> ('|', single vertical bar) for vectors.
>>
>> Thanks for anyones help!!
>>
>> Hassan
>
> a hint:
>
> help all;
> help any;
> help or;
>
> us

Adding on to us's hint:

help lt
help gt

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
reference us 15 Oct, 2009 15:19:05
logic operations El Hassan Abdel Fattah 15 Oct, 2009 14:54:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com