# Saving stored Solve output

my "lin" variable is a function of 2 variables: alpha and p1x.

   ptes = Solve[{x1, y1} \[Element]
lin[alpha0, p1x0] && {x1, y1} \[Element] rec1, {x1, y1}]


At the moment I perform the whole following operation for alpha=alpha0 and p1x=p1x0, saving the variables as such:

soltes = {x1, y1} /. ptes;
{p1xtes, p1ytes, p2xtes, p2ytes} = Flatten[soltes];

Dtes = ((p1xtes - p2xtes)^2 + (p1ytes - p2ytes)^2)^0.5


I have been making a few attempts at modifying the code so that Dtes remains a variable of alpha and p1x, without the slightest success. I am not sure on how to modify the code to carry on the variables dependence into Dtes, in other words to obtain Dtes[alpha_,p1x_]:= something[alpha,p1x]

ptes[alpha_, p1x_] = Solve[{x1, y1} \[Element] lin[alpha, p1x] && {x1, y1} \[Element] rec1, {x1, y1}]

soltes[alpha_, p1x_] = {x1, y1} /. ptes[alpha, p1x];

Dtes[alpha_, p1x_] = Norm[soltes[alpha, p1x][] - soltes[alpha, p1x][]];

• thanks, I used your answer as a first step to elaborate my solution. It is certainly not elegant, produces a lot of warnings, and I still do not understand it fully, but it returns the results I needed. I'll try to explain what I did in an answer to my post. – saimon Apr 17 at 21:37

If I understand your intentions correctly, I think Module function could be of use for you here. Perhaps something like this should work:

Dtes[\[Alpha]_Real,p1x_Real]:=Module[{ptes,soltes,p1xtes,p1ytes,p2xtes,p2ytes},
ptes = Solve[{x1, y1} \[Element] lin[\[Alpha], p1x] && {x1, y1} \[Element] rec1, {x1, y1}];
soltes = {x1, y1} /. ptes;
{p1xtes, p1ytes, p2xtes, p2ytes} = Flatten[soltes];
((p1xtes - p2xtes)^2 + (p1ytes - p2ytes)^2)^0.5
]

• I do not really understand the logic in there, but I have tries pasting this chunk of code into my own: I get no output, and 2 errors: (1) Syntax::tsntxi: "(*<<1>>" is incomplete; more input is needed. (2) Syntax::sntxi: "Incomplete expression; more input is needed \!(\"\")" – saimon Apr 17 at 14:09
• I'm not sure why that is, the above is just an example. I've used the functions that you have provided. I cannot validate my answer here because I don't know what your 'lin' function is, etc. As far as I'm concerned, the structure of the function I posted is correct. – amator2357 Apr 17 at 14:23

Thanks to Roman I was able to find a very clunky solution: - I had to switch from Solve to Reduce, cause for some reason Solve did not work when my line intersected the vertical edges of my rectangle - I looked for a way to access Reduce solutions, that, of course, was not the same that worked with Solve that Roman suggested - I redefined the distance since Norm could not work in the way I stored variables - I quieted the wheelbarrow of warnings that I got, despite obtaining the correct result - please refrain from laughing to hard at my solution, I am just a casual mathematica user

(*distance in the first rectangle*)
Quiet[ptes[alpha_, p1x_] =
Reduce[{x1, y1} \[Element] lin[alpha, p1x] && {x1, y1} \[Element]
rec1, {x1, y1}]];

Quiet[soltes[alpha_, p1x_] = {x1, y1} /. ptes[alpha, p1x]];

x1tes[alpha_, p1x_] := soltes[alpha, p1x][][][][];
x2tes[alpha_, p1x_] := soltes[alpha, p1x][][][][];
y1tes[alpha_, p1x_] := soltes[alpha, p1x][][][][];
y2tes[alpha_, p1x_] := soltes[alpha, p1x][][][][];

Quiet[Dtes[alpha_,
p1x_] := ((x1tes[alpha, p1x] -
x2tes[alpha, p1x])^2 + (y1tes[alpha, p1x] -
y2tes[alpha, p1x])^2)^0.5];

Quiet[Manipulate[
Dtes[alpha, p1x], {{alpha, alpha0}, 0.001,
90}, {{p1x, p1x0}, -Dxmax + 1, Dxmax}]]