1
$\begingroup$

Is it possible to evaluate an expresson on one line?

I have a linear algebra problem to re-write the straight line $-x=1-3y=-1-2z$ to a 'vector form';

line = {x, y, z} /. Solve[{{-x, 1 - 3 y, -1 - 2 z} == {1, 1, 1} t}, {x, y, z}][[1]];

and I want to extract the 'fix/start point' and the directional vector of line (in lack of better knowledge of any inbuilt functions in M.) by

t = 0;
p0 = line;
t = 1;
n = line - p0;

These 4 lines I think could be merged to two lines, but I don't know the syntax for it, something in the line of

p0 = line @{t=0};
n = line-p0 @{t=1};

What is the correct syntax for this?

$\endgroup$
  • $\begingroup$ mf67, may I suggest that you revisit your questions and consider accepting any answers that best solve your problem. $\endgroup$ – kglr Sep 22 '18 at 23:08
  • $\begingroup$ There is a blue popup 'flash' each time but I don't manage to read it before it disappears. Are there instructions somewhere to read to correctly process answers? $\endgroup$ – mf67 Sep 22 '18 at 23:54
  • $\begingroup$ mf67, this may be useful: Accepting an aswer: how does it work $\endgroup$ – kglr Sep 23 '18 at 0:00
3
$\begingroup$

You can use ReplaceAll with a list of lists of rules ({a->b}):

line /. {{t -> 0}, {t -> 1}}

{{0, 1/3, -(1/2)}, {-1, 0, -1}}

To get p0 and n in a single line:

{p0, n} = {#, #2 - #} & @@ (line /. {{t -> 0}, {t -> 1}})

{{0, 1/3, -(1/2)}, {-1, -(1/3), -(1/2)}}

Note: The same trick in a simpler example:

x /. {{x -> 100}, {x -> 5}, {x -> abc}}

{100, 5, abc}

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.