Here, I probably have a trivial case on how to use functions in Mathematica but I can't figure it out with the help of the Mathematica pages. I define the following function:
slope[x1_, x2_, y1_, y2_] := (y1 - y2)/(x1 - x2)
.
Then I want to evaluate this:
beta = slope[xp, xq, yp, yq].
I got:
Hold[beta = slope[xp, xq, yp, yq]],
which is definitely not what I wanted. I want to get $\frac{yp-yq}{xp-xq}$ out of it. ReleaseHold doesn't work. First I managed that by defining the function 'slope' without ':' in front of '='. After that, it wouldn't do that a second time so I tried defining the function with '$:=$' instead of only '='. Now nothing seems to work. Any helpful suggestion is highly appreciated.
EDIT: some function do their job now, magically ;-). But still, a new joke has risen. Begin to half of notebook:
In[1]:= phix[x_, y_] := y^2/x^2
In[2]:= phiy[x_, y_] := y (x^2 - b)/x^2
In[3]:= slope[x1_, x2_, y1_, y2_] := (y1 - y2)/(x1 - x2)
In[4]:= beta = slope[xp, xq, yp, yq]
Out[4]= (yp - yq)/(xp - xq)
In[5]:= linconst[x_, y_] := y - beta*x
In[6]:= gamma = linconst[xp, yp]
Out[6]= yp - (xp (yp - yq))/(xp - xq)
In[7]:= liney[x_] := beta*x + gamma
In[8]:= xr = beta^2 - (a + xp + xq)
Out[8]= -a - xp - xq + (yp - yq)^2/(xp - xq)^2
In[9]:= yp = liney[xp]
Out[9]= yp
In[10]:= yq = liney[xq]
During evaluation of In[10]:= $RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of -((xp (yp-yq))/(xp-xq)).
Out[10]= Hold[yp - (xp (yp - yq))/(xp - xq) + (xq (yp - yq))/(xp - xq)]
In[11]:= yr = liney[xr]
During evaluation of In[11]:= $RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of -((xp (yp-yq))/(xp-xq)).
Out[11]= Hold[yr = liney[xr]]
I have not defined any xp
or xq
. Only one Hold
has remained. Could be the cases that I can't plug in variables in a function that already uses this variable as a constant.
EDIT 2: why doesn't Mathematica simply handle beta
and gamma
as constants and compute yq=beta*xq+gamma
? Does it think that gamma and beta are functions or something?
xp
in terms ofbeta
? $\endgroup$gamma
in terms ofyp
andyp
in terms ofgamma
(indirectly throughliney
). It's the same as if you dida=b
thenb=a
. $\endgroup$