In the previous section we explained how the user can obtain information about a problem and its calling sequence. For the call itself, the function NetSolve[] is invoked with the problem name and its arguments. For example,
In[6]:= NetSolve[iqsort[{7,2,3,5,1}]]
contacting server merlin.comlab ...
Out[6]= {1, 2, 3, 5, 7} |
As stated earlier the user can pass not only numerical values, but also symbols that contain data of proper type or functions that return a result of this type. Indeed, Mathematica calculates these expressions and passes the arguments by value. For example
In[7]:= v = -Range[5]
Out[7]= {-1, -2, -3, -4, -5}
In[8]:= NetSolve[iqsort[v]]
contacting server merlin.comlab ...
Out[8]= {-5, -4, -3, -2, -1} |
In[9]:= NetSolve[iqsort[Table[Ceiling[10*Random[]], {7}]]]
contacting server merlin.comlab ...
Out[9]= {1, 2, 2, 2, 4, 6, 7} |
Since NetSolve[] is a function defined in Mathematica, it can be used in expressions like:
In[9]:= NetSolve[iqsort[Table[Ceiling[10*Random[]], {7}]]]
contacting server merlin.comlab ...
Out[9]= {1, 2, 2, 2, 4, 6, 7}
In[10]:= Print["The minimal element of v is ", NetSolve[iqsort[v]][[1]]]
contacting server merlin.comlab ...
The minimal element of v is -5 |
Let us consider a more complex problem such as the Level 3 BLAS subroutine dgemm[] which calculates where $op(X) = X$ or $op(X) = X'$.
The routine dgemm[] requires the following 7 arguments.
Let us generate three random matrices.
In[11]:= RandomMatrix[m_,n_] := Table[Ceiling[10*Random[]], {m}, {n}]
In[12]:= a = RandomMatrix[2,3]
Out[12]= {{9, 2, 3}, {6, 3, 9}}
In[13]:= b = RandomMatrix[3,2]
Out[13]= {{6, 4}, {4, 10}, {2, 9}}
In[14]:= c = RandomMatrix[2,2]
Out[14]= {{4, 7}, {4, 8}} |
In[15]:= NetSolve[dgemm["N", "N", 2, a, b, 3, c]]
contacting server cetus2a.cs.utk.edu ...
Out[15]= {{148., 187.}, {144., 294.}}
In[16]:= 2 a . b + 3 c
Out[16]= {{148, 187}, {144, 294}} |