Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16774

Re: Very simple question

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newspump.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From Alexei Boulbitch <Alexei.Boulbitch@iee.lu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Very simple question
Date Fri, 11 Apr 2014 06:11:18 +0000 (UTC)
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <li8126$adm$1@smc.vnet.net> (permalink)
Lines 79
Organization Time-Warner Telecom
NNTP-Posting-Date 11 Apr 2014 06:17:17 GMT
NNTP-Posting-Host 75ca9f1c.news.twtelecom.net
X-Trace DXC=Ulh@R[jA@0F06@:eWgm5?BC_A=>8kQj6M;[h;PUXBgbDj4eD5l`OG?OEFiONJ7[GoF2AQ5W1N^SNK
X-Complaints-To abuse@twtelecom.net
Xref csiph.com comp.soft-sys.math.mathematica:16774

Show key headers only | View raw


I've been away from Mathematica for about 7 years.
Can anyone tell me why function fx gives an error message but fy does
not? They look functionally the same to me.
Please send me an email about this.

fx[ptl_] := Module[{x1, y1, x2, y2, x3, y3},
   Print[pt1];
   x1 = pt1[[1, 1]]; y1 = pt1[[1, 2]];
   x2 = pt2[[2, 1]]; y2 = pt2[[2, 2]];
   x3 = pt3[[3, 1]]; y3 = pt3[[3, 2]];
   Print[x1, y1, x2, y2, x3, y3];
   ]
fx[{{1, 2}, {3, 5}, {4, 7}}]

fy[pt1_] := Module[{zz, x1, y1, x2, y2, x3, y3},
   zz = pt1;
   Print[zz];
   x1 = zz[[1, 1]]; y1 = zz[[1, 2]];
   x2 = zz[[2, 1]]; y2 = zz[[2, 2]];
   x3 = zz[[3, 1]]; y3 = zz[[3, 2]];
   Print[x1, y1, x2, y2, x3, y3]
   ]
fy[{{1, 2}, {3, 5}, {4, 7}}]

Thank you.
Steve Gray
stevebg at roadrunner.com




Hi, Stephen,

The answer is also simple: the body of the function fx calls pt2 and pt3 that are not defined anywhere. It confuses Mathematica. If you replace fx as follows:

fx[pt1_] := Module[{x1, y1, x2, y2, x3, y3},
 
  x1 = pt1[[1, 1]];
  y1 = pt1[[1, 2]];
  x2 = pt1[[2, 1]];
  y2 = pt1[[2, 2]];
  x3 = pt1[[3, 1]];
  y3 = pt1[[3, 2]];
  Print[x1, y1, x2, y2, x3, y3]]

Which is probably what you intended, it will return the result. In messages though. To see the result on the screen it is better to do something like the following:

fz[pt1_] := Module[{x1, y1, x2, y2, x3, y3},
 
  x1 = pt1[[1, 1]];
  y1 = pt1[[1, 2]];
  x2 = pt1[[2, 1]];
  y2 = pt1[[2, 2]];
  x3 = pt1[[3, 1]];
  y3 = pt1[[3, 2]];
  {x1, y1, x2, y2, x3, y3}]


fz[{{1, 2}, {3, 5}, {4, 7}}]

{1, 2, 3, 5, 4, 7}

Have fun, Alexei


Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar


Thread

Re: Very simple question Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2014-04-11 06:11 +0000

csiph-web