Skip to main content
Tweeted twitter.com/StackMma/status/1208356453444128770
Became Hot Network Question
edited title
Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Rsnfomly Randomly generated coordinates

added 2 characters in body; edited title
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

If statement with randomly Rsnfomly generated integerscoordinates

I am tasked withwant to code that will do the following exercise;:

Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; your definition should begin

randomHop[{x_, y_}] := 

The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then

  • if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
  • if r is 2, return {{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}.

I have so far tried

randomHop[{x_, y_}] := (
  r = RandomInteger[{1, 2}]
  If[r == 1, Return[{{0.5, 0.5}, {0.5, 0.5}}.{x, y}], 
  Return[{{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}]])

but it's not working, and I don't know why. Any help would be appreciated.

If statement with randomly generated integers

I am tasked with the following exercise;

Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; your definition should begin

randomHop[{x_, y_}] := 

The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then

  • if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
  • if r is 2, return {{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}.

I have so far tried

randomHop[{x_, y_}] := (
  r = RandomInteger[{1, 2}]
  If[r == 1, Return[{{0.5, 0.5}, {0.5, 0.5}}.{x, y}], 
  Return[{{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}]])

but it's not working, and I don't know why. Any help would be appreciated.

Rsnfomly generated coordinates

I want to code that will do the following:

Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; your definition should begin

randomHop[{x_, y_}] := 

The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then

  • if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
  • if r is 2, return {{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}.

I have so far tried

randomHop[{x_, y_}] := (
  r = RandomInteger[{1, 2}]
  If[r == 1, Return[{{0.5, 0.5}, {0.5, 0.5}}.{x, y}], 
  Return[{{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}]])

but it's not working, and I don't know why. Any help would be appreciated.

Improved formatting
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

I need to doam tasked with the following: exercise;

Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; your definition should begin

Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; your definition should begin

randomHop[{x_, y_}] :=

randomHop[{x_, y_}] := 

The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then

The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then

  • if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
  • if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
  • if r is 2, return {{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}.

I have so far tried

randomHop[{x_, y_}] := (
  r = RandomInteger[{1, 2}]
  If[r == 1, Return[{{0.5, 0.5}, {0.5, 0.5}}.{x, y}], 
  Return[{{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}]])

but it's not working, and I don't know why. Any help would be appreciated.

I need to do the following:

Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; your definition should begin

randomHop[{x_, y_}] :=

The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then

  • if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
  • if r is 2, return {{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}.

I have so far tried

randomHop[{x_, y_}] := (
  r = RandomInteger[{1, 2}]
  If[r == 1, Return[{{0.5, 0.5}, {0.5, 0.5}}.{x, y}], 
  Return[{{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}]])

but it's not working and I don't know why. Any help would be appreciated.

I am tasked with the following exercise;

Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; your definition should begin

randomHop[{x_, y_}] := 

The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then

  • if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
  • if r is 2, return {{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}.

I have so far tried

randomHop[{x_, y_}] := (
  r = RandomInteger[{1, 2}]
  If[r == 1, Return[{{0.5, 0.5}, {0.5, 0.5}}.{x, y}], 
  Return[{{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}]])

but it's not working, and I don't know why. Any help would be appreciated.

Source Link
Loading