<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885</link>
    <title>MATLAB Central Newsreader - Use of DPOSV function from Fortran</title>
    <description>Feed for thread: Use of DPOSV function from Fortran</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 11 Sep 2008 16:12:01 -0400</pubDate>
      <title>Use of DPOSV function from Fortran</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885#599911</link>
      <author>Sneha </author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
I have a function - 'dposv'  in fortran to be converted into Matlab. As I have read, we can use LAPACK functions but its giving an error- Undefined command/function 'dposv'.&lt;br&gt;
&lt;br&gt;
Can anyone help me out?&lt;br&gt;
&lt;br&gt;
It will be great help.&lt;br&gt;
&lt;br&gt;
Thanks...</description>
    </item>
    <item>
      <pubDate>Thu, 11 Sep 2008 18:39:02 -0400</pubDate>
      <title>Re: Use of DPOSV function from Fortran</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885#599944</link>
      <author>James Tursa</author>
      <description>&quot;Sneha &quot; &amp;lt;smithpamola@yahoo.com&amp;gt; wrote in message &amp;lt;gabg0h$l3a$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have a function - 'dposv'  in fortran to be converted into Matlab. As I have read, we can use LAPACK functions but its giving an error- Undefined command/function 'dposv'.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Can anyone help me out?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It will be great help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks...&lt;br&gt;
&lt;br&gt;
Not sure what you are doing. Are you:&lt;br&gt;
&lt;br&gt;
1) Taking Fortran code and converting it into MATLAB code (i.e., converting a ___.for file into a brand new m-file line by line&lt;br&gt;
&lt;br&gt;
or&lt;br&gt;
&lt;br&gt;
2) Trying to create a mex routine from the Fortran file ... i.e. call the Fortran routine from MATLAB.&lt;br&gt;
&lt;br&gt;
or&lt;br&gt;
&lt;br&gt;
3) Just trying to call an LAPACK or BLAS routine directly from MATLAB.&lt;br&gt;
&lt;br&gt;
It almost sounds like you have converted Fortran code to an m-file and now want to resolve the dposv call from within the m-file. Is this correct?&lt;br&gt;
&lt;br&gt;
If you want to call an LAPACK or BLAS routine from within an m-file, there are solutions for you on the FEX. Simply go here&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFileList.do&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFileList.do&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
and search for LAPACK or BLAS and you will see some solutions that may work for you. I haven't tried them all, but I have tried this one by Tim Toolan and it seems to work OK:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16777&amp;objectType=file&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16777&amp;objectType=file&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Thu, 11 Sep 2008 20:49:02 -0400</pubDate>
      <title>Re: Use of DPOSV function from Fortran</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885#599968</link>
      <author>Pam </author>
      <description>Hello James,&lt;br&gt;
&lt;br&gt;
Thank you so much for the help. Actually you got me right...I had the fortran program, I converted it but it gives an error that 'undefined function - dposv'.&lt;br&gt;
&lt;br&gt;
I am new to Matlab so can u elaborate more on that. I tried to run 'mex lapack.c' in Matlab (in windows) as he mentioned but it gives me an error again - &lt;br&gt;
'??? Error using ==&amp;gt; mex&lt;br&gt;
Unable to complete successfully'.&lt;br&gt;
&lt;br&gt;
I understood that we need to pass no of arguments as many they are in original function.&lt;br&gt;
dot = lapack('Z=ZDOTC(i,z,i,z,i)', length(x), x, 1, y, 1);&lt;br&gt;
Now, i,z are just undefiend varibales, right? I mean they first i=length(x), z =x,.... right?&lt;br&gt;
&lt;br&gt;
I have original dposv function like this:&lt;br&gt;
dposv('A',6,1,a,6,b,12,c);&lt;br&gt;
Now, I want it to work with Matlab. :(&lt;br&gt;
&lt;br&gt;
Thanks again...&lt;br&gt;
-Pam&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;James Tursa&quot; &amp;lt;aclassyguywithaknotac@hotmail.com&amp;gt; wrote in &lt;br&gt;
message &amp;lt;gabok6$2d2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Sneha &quot; &amp;lt;smithpamola@yahoo.com&amp;gt; wrote in message &amp;lt;gabg0h$l3a$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hello,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I have a function - 'dposv'  in fortran to be converted into Matlab. As I have read, we can use LAPACK functions but its giving an error- Undefined command/function 'dposv'.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Can anyone help me out?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; It will be great help.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Not sure what you are doing. Are you:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1) Taking Fortran code and converting it into MATLAB code (i.e., converting a ___.for file into a brand new m-file line by line&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; or&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2) Trying to create a mex routine from the Fortran file ... i.e. call the Fortran routine from MATLAB.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; or&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 3) Just trying to call an LAPACK or BLAS routine directly from MATLAB.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It almost sounds like you have converted Fortran code to an m-file and now want to resolve the dposv call from within the m-file. Is this correct?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you want to call an LAPACK or BLAS routine from within an m-file, there are solutions for you on the FEX. Simply go here&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFileList.do&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFileList.do&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and search for LAPACK or BLAS and you will see some solutions that may work for you. I haven't tried them all, but I have tried this one by Tim Toolan and it seems to work OK:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16777&amp;objectType=file&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16777&amp;objectType=file&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; James Tursa&lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Thu, 11 Sep 2008 21:08:02 -0400</pubDate>
      <title>Re: Use of DPOSV function from Fortran</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885#599971</link>
      <author>Pam </author>
      <description>Hello James,&lt;br&gt;
&lt;br&gt;
I got the program now. As fas as I understand it, I don't think I can't pass matrix as an argument and as I mentioned my function is:&lt;br&gt;
dposv('A',6,1,a,6,b,12,c);&lt;br&gt;
where a and b are matrix :(&lt;br&gt;
&lt;br&gt;
Any idea how to do that?&lt;br&gt;
&lt;br&gt;
-Pam</description>
    </item>
    <item>
      <pubDate>Fri, 12 Sep 2008 07:24:02 -0400</pubDate>
      <title>Re: Use of DPOSV function from Fortran</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885#600024</link>
      <author>James Tursa</author>
      <description>&quot;Pam &quot; &amp;lt;smithpamola@yahoo.com&amp;gt; wrote in message &amp;lt;gac07u$2va$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello James,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you so much for the help. Actually you got me right...I had the fortran program, I converted it but it gives an error that 'undefined function - dposv'.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am new to Matlab so can u elaborate more on that. I tried to run 'mex lapack.c' in Matlab (in windows) as he mentioned but it gives me an error again - &lt;br&gt;
&amp;gt; '??? Error using ==&amp;gt; mex&lt;br&gt;
&amp;gt; Unable to complete successfully'.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I understood that we need to pass no of arguments as many they are in original function.&lt;br&gt;
&amp;gt; dot = lapack('Z=ZDOTC(i,z,i,z,i)', length(x), x, 1, y, 1);&lt;br&gt;
&amp;gt; Now, i,z are just undefiend varibales, right? I mean they first i=length(x), z =x,.... right?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have original dposv function like this:&lt;br&gt;
&amp;gt; dposv('A',6,1,a,6,b,12,c);&lt;br&gt;
&amp;gt; Now, I want it to work with Matlab. :(&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks again...&lt;br&gt;
&amp;gt; -Pam&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
OK. First I will tell you how to call the LAPACK routine as you requested ... and then I will tell you the easy way.&lt;br&gt;
&lt;br&gt;
1) As you requested ...&lt;br&gt;
&lt;br&gt;
First download the lapack files from the FEX (looks like you already did this). Make sure the files are somewhere on the MATLAB path, and change your default directory to be that directory. Then to mex the file, do this:&lt;br&gt;
&lt;br&gt;
mex -setup&lt;br&gt;
(then press Enter)&lt;br&gt;
(then select a C compiler, such as lcc)&lt;br&gt;
(then press Enter a couple more times)&lt;br&gt;
mex lapack.c&lt;br&gt;
&lt;br&gt;
You should get a lapack.mexw32 file. This is the actual dll file that will be executed. If you are not on a Windows system, then the instructions in the lapack.c file say to do this (I haven't tried this, since I have a Windows system):&lt;br&gt;
&lt;br&gt;
mex -ldl lapack.c&lt;br&gt;
&lt;br&gt;
Once you have the mex routine built, here is an example sequence of commands to call the LAPACK DPOSV function from the MATLAB workspace using the same variable sizes and names that you were using:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; a = rand(6,6)&lt;br&gt;
&lt;br&gt;
a =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.5466    0.5226    0.8757    0.2987    0.5828    0.5798&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.4449    0.8801    0.7373    0.6614    0.4235    0.7604&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6946    0.1730    0.1365    0.2844    0.5155    0.5298&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6213    0.9797    0.0118    0.4692    0.3340    0.6405&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.7948    0.2714    0.8939    0.0648    0.4329    0.2091&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.9568    0.2523    0.1991    0.9883    0.2259    0.3798&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; a = a'*a  % ensure pos def&lt;br&gt;
&lt;br&gt;
a =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2.9124    1.8632    1.8098    1.9438    1.6328    1.9507&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.8632    2.1749    1.4346    1.5142    1.2682    1.8440&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.8098    1.4346    2.1680    1.0484    1.3289    1.4108&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.9438    1.5142    1.0484    1.8088    1.0089    1.5163&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.6328    1.2682    1.3289    1.0089    1.1347    1.3233&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.9507    1.8440    1.4108    1.5163    1.3233    1.7933&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; b = rand(12,1)&lt;br&gt;
&lt;br&gt;
b =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.7833&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6808&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.4611&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.5678&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.7942&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0592&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6029&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0503&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.4154&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.3050&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.8744&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0150&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; c = 0&lt;br&gt;
&lt;br&gt;
c =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; [out1 out2 out3] = lapack('DPOSV(h,i,i,D,i,D,i,I)','U',6,1,a,6,b,12,c)&lt;br&gt;
&lt;br&gt;
out1 =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.7066    1.0918    1.0605    1.1390    0.9568    1.1431&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.8632    0.9914    0.2792    0.2729    0.2255    0.6012&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.8098    1.4346    0.9826   -0.2399    0.2558    0.0313&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.9438    1.5142    1.0484    0.6160   -0.1316    0.0938&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.6328    1.2682    1.3289    1.0089    0.2929    0.3360&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.9507    1.8440    1.4108    1.5163    1.3233    0.0509&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
out2 =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;-116.1058&lt;br&gt;
&amp;nbsp;&amp;nbsp;102.8057&lt;br&gt;
&amp;nbsp;&amp;nbsp;-62.7881&lt;br&gt;
&amp;nbsp;&amp;nbsp;145.5830&lt;br&gt;
&amp;nbsp;&amp;nbsp;422.0414&lt;br&gt;
&amp;nbsp;-364.5099&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6029&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0503&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.4154&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.3050&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.8744&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0150&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
out3 =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
&lt;br&gt;
Note that the vector b is 12x1 but we only used the first 6x1 part of it according to your function call, so I did the same. Thus, the answer in out2 only has a result for the first 6x1 part as expected.&lt;br&gt;
&lt;br&gt;
If you can't get lapack.c compiled and working properly, then a custom C mex file could be built that calls the DPOSV subroutine to get your answer.&lt;br&gt;
&lt;br&gt;
An explanation of this:&lt;br&gt;
&lt;br&gt;
[out1 out2 out3] = lapack('DPOSV(h,i,i,D,i,D,i,I)','U',6,1,a,6,b,12,c)&lt;br&gt;
&lt;br&gt;
DPOSV is the subroutine to be called. The argument prototype works like this (small case means input only, large caps case means output and possibly also an input). I constructed this prototype myself by reading the LAPACK documentation for the DPOSV subroutine:&lt;br&gt;
&lt;br&gt;
h = The first argument is a character input&lt;br&gt;
i = The second argument is an integer input&lt;br&gt;
i = The third argument is an integer input&lt;br&gt;
D = The fourth argument is a double output/input&lt;br&gt;
i = The fifth argument is an integer input&lt;br&gt;
D = The sixth argument is a double output/input&lt;br&gt;
i = The seventh argument is an integer input&lt;br&gt;
I = The eighth argument is an integer output/input&lt;br&gt;
&lt;br&gt;
Then after the character string describing the prototype, you list the arguments. I could not find the option 'A' that you were using in the DPOSV documentation, so I used 'U' meaning that the input data is in the upper triangular portion of A (actually I could have also used 'L' in this case since the data is in both places). Then I just listed the other arguments. Since there are three CAP letters in the prototype, that means I am expecting three outputs, so I use [out1 out2 out3] to capture them. You do not have to convert MATLAB double variables to int32 variables in those spots where DPOSV is expecting an integer ... the lapack function will do this automatically for you inside the mex routine (nice!).&lt;br&gt;
&lt;br&gt;
2) The easy way ...&lt;br&gt;
&lt;br&gt;
I checked the doc for DPOSV and it states that this routine simply computes the solution to a real system of linear equations A * X = B, where A is an n-by-n symmetric positive definite matrix and X and B are n-by-nrhs matrices. Well, since all you are doing is solving a system of linear equations you can forget all about that lapack stuff I just showed you and simply use the MATLAB built in backslash operator to solve the system of equations. MATLAB is very good at solving systems of linear equations:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; a\b(1:6)&lt;br&gt;
&lt;br&gt;
ans =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;-116.1058&lt;br&gt;
&amp;nbsp;&amp;nbsp;102.8057&lt;br&gt;
&amp;nbsp;&amp;nbsp;-62.7881&lt;br&gt;
&amp;nbsp;&amp;nbsp;145.5830&lt;br&gt;
&amp;nbsp;&amp;nbsp;422.0414&lt;br&gt;
&amp;nbsp;-364.5099&lt;br&gt;
&lt;br&gt;
Same answer as before. Nicer!&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Fri, 12 Sep 2008 15:18:01 -0400</pubDate>
      <title>Re: Use of DPOSV function from Fortran</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885#600104</link>
      <author>Pam </author>
      <description>&quot;James Tursa&quot; &amp;lt;aclassyguywithaknotac@hotmail.com&amp;gt; wrote in message &amp;lt;gad5ei$hkh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Pam &quot; &amp;lt;smithpamola@yahoo.com&amp;gt; wrote in message &amp;lt;gac07u$2va$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hello James,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thank you so much for the help. Actually you got me right...I had the fortran program, I converted it but it gives an error that 'undefined function - dposv'.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I am new to Matlab so can u elaborate more on that. I tried to run 'mex lapack.c' in Matlab (in windows) as he mentioned but it gives me an error again - &lt;br&gt;
&amp;gt; &amp;gt; '??? Error using ==&amp;gt; mex&lt;br&gt;
&amp;gt; &amp;gt; Unable to complete successfully'.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I understood that we need to pass no of arguments as many they are in original function.&lt;br&gt;
&amp;gt; &amp;gt; dot = lapack('Z=ZDOTC(i,z,i,z,i)', length(x), x, 1, y, 1);&lt;br&gt;
&amp;gt; &amp;gt; Now, i,z are just undefiend varibales, right? I mean they first i=length(x), z =x,.... right?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I have original dposv function like this:&lt;br&gt;
&amp;gt; &amp;gt; dposv('A',6,1,a,6,b,12,c);&lt;br&gt;
&amp;gt; &amp;gt; Now, I want it to work with Matlab. :(&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks again...&lt;br&gt;
&amp;gt; &amp;gt; -Pam&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; OK. First I will tell you how to call the LAPACK routine as you requested ... and then I will tell you the easy way.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1) As you requested ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; First download the lapack files from the FEX (looks like you already did this). Make sure the files are somewhere on the MATLAB path, and change your default directory to be that directory. Then to mex the file, do this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; mex -setup&lt;br&gt;
&amp;gt; (then press Enter)&lt;br&gt;
&amp;gt; (then select a C compiler, such as lcc)&lt;br&gt;
&amp;gt; (then press Enter a couple more times)&lt;br&gt;
&amp;gt; mex lapack.c&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You should get a lapack.mexw32 file. This is the actual dll file that will be executed. If you are not on a Windows system, then the instructions in the lapack.c file say to do this (I haven't tried this, since I have a Windows system):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; mex -ldl lapack.c&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Once you have the mex routine built, here is an example sequence of commands to call the LAPACK DPOSV function from the MATLAB workspace using the same variable sizes and names that you were using:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; a = rand(6,6)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     0.5466    0.5226    0.8757    0.2987    0.5828    0.5798&lt;br&gt;
&amp;gt;     0.4449    0.8801    0.7373    0.6614    0.4235    0.7604&lt;br&gt;
&amp;gt;     0.6946    0.1730    0.1365    0.2844    0.5155    0.5298&lt;br&gt;
&amp;gt;     0.6213    0.9797    0.0118    0.4692    0.3340    0.6405&lt;br&gt;
&amp;gt;     0.7948    0.2714    0.8939    0.0648    0.4329    0.2091&lt;br&gt;
&amp;gt;     0.9568    0.2523    0.1991    0.9883    0.2259    0.3798&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; a = a'*a  % ensure pos def&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     2.9124    1.8632    1.8098    1.9438    1.6328    1.9507&lt;br&gt;
&amp;gt;     1.8632    2.1749    1.4346    1.5142    1.2682    1.8440&lt;br&gt;
&amp;gt;     1.8098    1.4346    2.1680    1.0484    1.3289    1.4108&lt;br&gt;
&amp;gt;     1.9438    1.5142    1.0484    1.8088    1.0089    1.5163&lt;br&gt;
&amp;gt;     1.6328    1.2682    1.3289    1.0089    1.1347    1.3233&lt;br&gt;
&amp;gt;     1.9507    1.8440    1.4108    1.5163    1.3233    1.7933&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; b = rand(12,1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; b =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     0.7833&lt;br&gt;
&amp;gt;     0.6808&lt;br&gt;
&amp;gt;     0.4611&lt;br&gt;
&amp;gt;     0.5678&lt;br&gt;
&amp;gt;     0.7942&lt;br&gt;
&amp;gt;     0.0592&lt;br&gt;
&amp;gt;     0.6029&lt;br&gt;
&amp;gt;     0.0503&lt;br&gt;
&amp;gt;     0.4154&lt;br&gt;
&amp;gt;     0.3050&lt;br&gt;
&amp;gt;     0.8744&lt;br&gt;
&amp;gt;     0.0150&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; c = 0&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; c =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;      0&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; [out1 out2 out3] = lapack('DPOSV(h,i,i,D,i,D,i,I)','U',6,1,a,6,b,12,c)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; out1 =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     1.7066    1.0918    1.0605    1.1390    0.9568    1.1431&lt;br&gt;
&amp;gt;     1.8632    0.9914    0.2792    0.2729    0.2255    0.6012&lt;br&gt;
&amp;gt;     1.8098    1.4346    0.9826   -0.2399    0.2558    0.0313&lt;br&gt;
&amp;gt;     1.9438    1.5142    1.0484    0.6160   -0.1316    0.0938&lt;br&gt;
&amp;gt;     1.6328    1.2682    1.3289    1.0089    0.2929    0.3360&lt;br&gt;
&amp;gt;     1.9507    1.8440    1.4108    1.5163    1.3233    0.0509&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; out2 =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  -116.1058&lt;br&gt;
&amp;gt;   102.8057&lt;br&gt;
&amp;gt;   -62.7881&lt;br&gt;
&amp;gt;   145.5830&lt;br&gt;
&amp;gt;   422.0414&lt;br&gt;
&amp;gt;  -364.5099&lt;br&gt;
&amp;gt;     0.6029&lt;br&gt;
&amp;gt;     0.0503&lt;br&gt;
&amp;gt;     0.4154&lt;br&gt;
&amp;gt;     0.3050&lt;br&gt;
&amp;gt;     0.8744&lt;br&gt;
&amp;gt;     0.0150&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; out3 =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;            0&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Note that the vector b is 12x1 but we only used the first 6x1 part of it according to your function call, so I did the same. Thus, the answer in out2 only has a result for the first 6x1 part as expected.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you can't get lapack.c compiled and working properly, then a custom C mex file could be built that calls the DPOSV subroutine to get your answer.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; An explanation of this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [out1 out2 out3] = lapack('DPOSV(h,i,i,D,i,D,i,I)','U',6,1,a,6,b,12,c)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; DPOSV is the subroutine to be called. The argument prototype works like this (small case means input only, large caps case means output and possibly also an input). I constructed this prototype myself by reading the LAPACK documentation for the DPOSV subroutine:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; h = The first argument is a character input&lt;br&gt;
&amp;gt; i = The second argument is an integer input&lt;br&gt;
&amp;gt; i = The third argument is an integer input&lt;br&gt;
&amp;gt; D = The fourth argument is a double output/input&lt;br&gt;
&amp;gt; i = The fifth argument is an integer input&lt;br&gt;
&amp;gt; D = The sixth argument is a double output/input&lt;br&gt;
&amp;gt; i = The seventh argument is an integer input&lt;br&gt;
&amp;gt; I = The eighth argument is an integer output/input&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Then after the character string describing the prototype, you list the arguments. I could not find the option 'A' that you were using in the DPOSV documentation, so I used 'U' meaning that the input data is in the upper triangular portion of A (actually I could have also used 'L' in this case since the data is in both places). Then I just listed the other arguments. Since there are three CAP letters in the prototype, that means I am expecting three outputs, so I use [out1 out2 out3] to capture them. You do not have to convert MATLAB double variables to int32 variables in those spots where DPOSV is expecting an integer ... the lapack function will do this automatically for you inside the mex routine (nice!).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2) The easy way ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I checked the doc for DPOSV and it states that this routine simply computes the solution to a real system of linear equations A * X = B, where A is an n-by-n symmetric positive definite matrix and X and B are n-by-nrhs matrices. Well, since all you are doing is solving a system of linear equations you can forget all about that lapack stuff I just showed you and simply use the MATLAB built in backslash operator to solve the system of equations. MATLAB is very good at solving systems of linear equations:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; a\b(1:6)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  -116.1058&lt;br&gt;
&amp;gt;   102.8057&lt;br&gt;
&amp;gt;   -62.7881&lt;br&gt;
&amp;gt;   145.5830&lt;br&gt;
&amp;gt;   422.0414&lt;br&gt;
&amp;gt;  -364.5099&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Same answer as before. Nicer!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; James Tursa&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
---------------&lt;br&gt;
Hey James,&lt;br&gt;
&lt;br&gt;
Thanks a lot!&lt;br&gt;
Its a great help. I really appreciate it.&lt;br&gt;
&lt;br&gt;
For option 2, it does not work for a=12*12 and b=1*12 matrix. I tried a\b(12:1), but that doesn't work either. Let me know if you have any idea about it.&lt;br&gt;
&lt;br&gt;
Thanks a million....&lt;br&gt;
&lt;br&gt;
-Pam</description>
    </item>
    <item>
      <pubDate>Fri, 12 Sep 2008 21:40:04 -0400</pubDate>
      <title>Re: Use of DPOSV function from Fortran</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235885#600160</link>
      <author>James Tursa</author>
      <description>&quot;Pam &quot; &amp;lt;smithpamola@yahoo.com&amp;gt; wrote in message &amp;lt;gae179$jpo$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ---------------&lt;br&gt;
&amp;gt; Hey James,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a lot!&lt;br&gt;
&amp;gt; Its a great help. I really appreciate it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; For option 2, it does not work for a=12*12 and b=1*12 matrix. I tried a\b(12:1), but that doesn't work either. Let me know if you have any idea about it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a million....&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Pam&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
If a is 12*12, then b would have to be 12*1, not 1*12. And, in that case, you again would simply type in a\b, not a\b(12:1). MATLAB will be able to solve a 12*12 just fine.&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
  </channel>
</rss>

