mm-166 Can anyone point me to some good online references or better yet sometested code (C or FORTRAN) for calculating slepian functions or prolatespheroidal wave functions?They seem to be very difficult to evaluate accurately over an arbitrarydomain. There are some functions in Matlab to evaluate them from -1to 1 but I have my doubts about the approve@localhost) by support1.mathforum.org (8.11.6/8.11.6/The Math Forum, $Revision: 1.9 primary) id ON TUESDAY HE averaged12 miles per hour more, and it took him 9 minutes less to get towork.How far does he travel to (miles/hr)D = distance (miles)S * (45 / 60) = D(S + 12) * ((45-9)/60) = DSo,S * (45/60) = (S+12) *(36/60), which implies S=48 miles/hr.Hence, D= 48 * (45/60) = 36 miles.You better not be cheating on homework. If you are, you should feel veryguilty.> On Monday, Roger drove to work in 45 minutes. ON TUESDAY HE averaged> 12 miles per hour more, and it took him 9 minutes less to get to> work.How far does he travel to work?> support1.mathforum.org (8.11.6/8.11.6/The Math Forum, by support1.mathforum.org (8.11.6/8.11.6/The Math Forum, only the non-zero entries of a sparse matrix using the expression: ij=(row-1)*matrix_size +columns. Is it possibleto reconstruct the the row and the columns of the matrix dependingonly on the index, ij. Where matrix_size is the size of a given squarematrix. This is becuase I can not save the row and the columns of eachentry in the first pass of my program.I have tried to find the row and the columns like this:columns=ij-matrix_size*INT(ij/matrix_size)row=INT(( ij-columns)/matrix_size)+columns, where INT produce theinteger part of the expressions above.I, however, did not quite get the right answer ? Is there any one outthere who can comment on it have indexed only the non-zero entries of a sparse matrix >using the expression: ij=(row-1)*matrix_size +columns. Is it possible >to reconstruct the the row and the columns of the matrix depending >only on the index, ij. Where matrix_size is the size of a given square >matrix. This is becuase I can not save the row and the columns of each >entry in the first pass of my program. >I have tried to find the row and the columns like this: >columns=ij-matrix_size*INT(ij/matrix_size) >row=INT((ij-columns)/matrix_size)+columns, where INT produce the >integer part of the expressions above. >I, however, did not quite get the right answer ? Is there any one out >there who can comment on it ? >Yacob >aren't there many i and j which make ij=k constant ? hence I cannot see how you may reconstruct two values i and j from one k without knowing some problem by now, but your post showed up on ournews server again this evening, so this gives me a convenient time to saythat I made an error in my initial reply. (I forgot to take into accountthat your rows and columns are indexed 1 to n rather than 0 to n-1.)This makesrow=INT(ij/matrix_size)+1 = INT( (row-1) + column/matrix_size) + 1 = row + INT(column/matrix_size)give the wrong answer when columns=matrix_size (sinceINT(column/matrix_size) will not be 0 in that case).The correct solution should have beenrow =INT((ij-1)/matrix_size) + 1column = ij - (row-1)*matrix_sizeThat'll teach me not to post without coffee.Rick>> I have indexed only the non-zero entries of a sparse matrix> using the expression: ij=(row-1)*matrix_size +columns. Is it possible> to reconstruct the the row and the columns of the matrix depending> only on the index, ij. Where matrix_size is the size of a given square> matrix. This is becuase I can not save the row and the columns of each> entry in the first pass of my program.>> I have tried to find the row and the columns like this:>> columns=ij-matrix_size*INT(ij/matrix_size)> row=INT((ij-columns)/matrix_size)+columns, where INT produce the> integer part of the expressions above.>> I, however, did not quite get the right answer ? Is there any one out> there approve@localhost) by support1.mathforum.org (8.11.6/8.11.6/The Math Forum, $Revision: 1.9 primary) id approve@localhost) by support1.mathforum.org (8.11.6/8.11.6/The Math Forum, $Revision: 1.9 primary) id During my recentwork, I want to find the exact form of the sum or multiply of I_0. orfind the maximum of the following function:f(x)=prod_{n=-N}^{N}1/Msum_{m=0}^{M-1}(I_0(x*cos( 2pi*m/M*n))+I_0(x*sin(2pi*m/M*n)))Any good approximation approve@localhost) by support1.mathforum.org (8.11.6/8.11.6/The Math Forum, $Revision: 1.9 primary) id that can do a complex 3000 point inplace fft. I don't have Everyone,> I need the source code in C that can do a complex 3000 point in> place fft. I don't have much memory to work with so the smaller the> AlexIf you want a comprehensable fft that doesn't take a week to figureout how to install (not mentioning any names here...), you could doworse than fftn.File at a comprehensable fft that doesn't take a week to figure> out how to install (not mentioning any names here...), you could do> worse than fftn.If you get an old version of FFTW, such as 2.x, then you can justcopy all the source files to a single directory and compile them there.Compiling 3.0 is Everyone, > I need the source code in C that can do a complex 3000 point in >place fft. I don't have much memory to work with so the smaller the >Alex >what about fftw3: http://www.fftw.orgif this is too ambitious for you, then you Everyone,> I need the source code in C that can do a complex 3000 point in> place fft. I don't have much memory to work with so the smaller the> AlexCheck out support1.mathforum.org (8.11.6/8.11.6/The Math Forum, calculate the integral of 1/(1 - x^4)^(1/2). This is a tricky one. Anyone got any ideas? I'd really appreciate CUNGQR was my first major problem. The second wasthat my version of MATLAB (5.3.0.10183) is producing slightly differentresults, numerically. I don't think it's just a precision issue. Somethingappears to have changed across know that after version 5.3, Matlab switched the core matrix computationlibrary from LINPACK/EISPACK to LAPACK. So, my version of Matlab isessentially using the same source code as my Fortran LAPACK library (whichis cxml.lib under Compaq Visual Fortran). You can read about the switch atthe Mathworks website (www.mathworks.com) - just do a search on LAPACK.http://www.mathworks.com/company/newsletter/ clevescorner/winter2000.cleve.shtml In any case, while there may be small numerical differences between Matlab5.3 and the current LAPACK 3.0, I would expect them to be _very_ small for aQR decomposition. Another thing to remember is that Matlab does everythingin double precision, whereas the LAPACK routines you're using are singleprecision, so that could be the cause of any differences you've seen. Youcan try using the ZGEQRF and ZUNGRQ routines from LAPACK instead (theequivalent of double precision complex), but make sure you declare yourinput matrices to be double precision as well.John>> Using CUNGRQ instead of CUNGQR was my first major problem. The second was> that my version of MATLAB (5.3.0.10183) is producing slightly different> results, numerically. I don't think it's just a precision issue. Something> appears to have changed across releases.>> What version of MATLAB are you using?> symmetric positive> matrix with 1's on the diagonals, and with eigenvalues that I can> pre-specify.>> If I do (in matlab)> u=rand(3,3); % 3 by 3 matrix of u(0,1)> H=orth(u); % orthonormal basis of u> D=diag([.4 0 0]) the true eigenvalues are .4 0 0> x=H*D*H' % covariance matrix>> and then I do svd(x), the eigenvalues of x are .4,0,0 as expected.>> Is there some way to do a similar for the correlation matrix (with 1> on the diagonals) and still allow me to specify the eigenvalue?>You will find a discussion of such inGeorge Marsaglia and Ingram Olkin, ``Generating correlation You will find a discussion of such in> George Marsaglia and Journ. Scient. and Statistical . Computing v 5 , 470--475, 1984,> George, - I am able to use a specific, but much more simple solution, which I implemented in my factor-analysis-program (just for experimental reasons those days). Since you're surely familiar with the optimization criterion, which is needed to compute the rotation-angles for getting the PCA-position of a given loadings-matrix, I'll say, the solution is just a small modification of that criterion. I implemented this under the rationale to get equal sums-of-squares-of-loadings (Equal SSqL) of the factors; somehow opposite to that of the PC-rotation, where you optimize for maximum SSqL in the first factor and minimum in the second. This procedure converges as fast as PC-rotation and can be used optimally for this job.GottfriedExampleLet D be the desired diagonal-matrix containing the Eigenvalues: 1.60 0.00 0.00 0.00 0.00 1.20 0.00 0.00 0.00 0.00 0.80 0.00 0.00 0.00 0.00 0.40then its root can be used for the common rotation-process (just as a degenerate loadingsmatrix)D2 (D2*D2=D) 1.26 0.00 0.00 0.00 0.00 1.10 0.00 0.00 0.00 0.00 0.89 0.00 0.00 0.00 0.00 0.63You apply a column-rotation T to D2 for getting equal SSqL ineach column. This rotation produces this loadingsmatrix:L = D2 * TL 0.89 0.13 -0.88 0.15 -0.08 0.76 -0.11 -0.78 -0.01 0.64 0.19 0.60 0.45 -0.01 0.43 -0.12Once you have T you can create the desired correlation-matrixR by either computing R = L'*Lor (which is equivalent) R = T' * D * T 1.00 0.04 -0.58 0.14 0.04 1.00 -0.08 -0.19 -0.58 -0.08 1.00 0.01 0.14 -0.19 0.01 1.00(Rotation-method Equal-Sqared-Loadings-sums in my factor-analysis- tools Inside-[R] & MatMate (both small handmade programs for study of Matrix/factor-analysis techniques))The rotation-criterion is the same summing of loadingssquares likein PC-rotation, but the angle to be rotated is then just enhancedby 90 deg, so x/y-axis are exchanged to y/-x, and the iterationconverges to minimal should provide a bit more accurate data:Gottfried Helms containing the Eigenvalues: 1.600 0.000 0.000 0.000 0.000 1.200 0.000 0.000 0.000 0.000 0.800 0.000 0.000 0.000 0.000 0.400> then its root can be used for the common rotation-process> (just as a degenerate loadingsmatrix)> D2 (D2*D2=D) 1.265 0.000 0.000 0.000 0.000 1.095 0.000 0.000 0.000 0.000 0.894 0.000 0.000 0.000 0.000 0.632> You apply a column-rotation T to D2 for getting equal SSqL in> each column. This rotation produces this loadingsmatrix:> L = D2 * T> L 0.865 0.233 0.893 -0.023 0.229 -0.732 -0.011 0.782 -0.088 0.636 -0.065 0.620 -0.438 -0.076 0.446 0.063> Once you have T you can create the desired correlation-matrix> R by either computing> R = L'*L> or (which is equivalent)> R = T' * D * T 1.000 0.011 0.580 0.078 0.011 1.000 0.141 -0.189 0.580 0.141 1.000 -0.041 0.078 -0.189 -0.041 1.000and L*L' = 1.600 0.000 -0.000 0.000 0.000 1.200 0.000 -0.000 -0.000 0.000 0.800 0.000 0.000 -0.000 0.000 0.400There are some differences, which are so high, that I haveto check about the uniqueness of this squares problem where the model functions are essentially of the form:yi=a0*exp(a1+a2/xi) + a3*exp(a4+a5/xi) + .....(This is the sum of a number of first order kinetics processes where temperature (x) changes with time.)The number of exp-terms is between 1 and 6 and the number of xi,yi is between 64 and 256.This problem is, at least in my case, very ill conditioned in the sense that the Hessian matrix (and thus the variance co-variance matrix) has a very small determinant and the ratio between largest and smallest eigenvalue is very large. In addition to that are the parameters a1 and a2, a4 and a5 and so on, highly intercorrelated. Problems which I think are linked.Is there a trick, e.g. changing of variables, that least squares problem where the model functions are >essentially of the form: >yi=a0*exp(a1+a2/xi) + a3*exp(a4+a5/xi) + ..... >(This is the sum of a number of first order kinetics processes where >temperature (x) changes with time.) >The number of exp-terms is between 1 and 6 and the number of xi,yi is >between 64 and 256. >This problem is, at least in my case, very ill conditioned in the sense >that the Hessian matrix (and thus the variance co-variance matrix) has a >very small determinant and the ratio between largest and smallest >eigenvalue is very large. In addition to that are the parameters a1 and >a2, a4 and a5 and so on, highly intercorrelated. Problems which I think >are linked. >Is there a trick, e.g. changing of variables, that could improve suggestions, >Janwillem >as said already by Brian, he parameters a1, a4, ... are redundant. this willcause already singularity in your Jacobian.Nevertheless, as rnold stated , a six-term exponential fit is a quiteambitious undertaking. the job might possibly become easier ifyou observe the partial separability of the problem, which allows you toexpress a0, a3, (the factors before the exp) as functions of theparameters appearing inside the exp: given those, you can solve for the others by a linear least squares problem. hence you may use an appropriate software (dqed) or minimize in alternation: guess the nonlinear parameters,solve for the linear ones, then guess again the nonlinear ones ..there is ready to use software for your task, seehttp://plato.la.asu.edu/topics/problems/nlolsq.htmlhthpeter functions are >essentially of the form:>>yi=a0*exp(a1+a2/xi) + a3*exp(a4+a5/xi) + .....>>(This is the sum of a number of first order kinetics processes where >temperature (x) changes with time.)>>The number of exp-terms is between 1 and 6 and the number of xi,yi is >between 64 and 256.>>This problem is, at least in my case, very ill conditioned in the sense >that the Hessian matrix (and thus the variance co-variance matrix) has a >very small determinant and the ratio between largest and smallest >eigenvalue is very large. In addition to that are the parameters a1 and >a2, a4 and a5 and so on, highly intercorrelated. Problems which I think >are linked.>>Is there a trick, e.g. changing of variables, that could improve the >behaviour of the system.Ill-conditioning is a feature of the problem that you're trying to solverather than an aspect of the algorithm you used to solve it. In otherwords, the ill-conditioning is telling you that the available data doesn'tprovide much information about the values of the parameters. The ill-conditioning will show up when you compute confidence intervalsfor the fitted parameters (you will compute confidence intervals, right?) inthe form of very broad confidence intervals. Answers like a1=10 plus orminus 50 might not be very helpful.In this case, some of the difficulty comes from the problem formulation.Considering the first term only, a0*exp(a1+a2/xi)=a0*exp(a1)*exp(a2/xi) a0*exp(a1+a2/xi)=(a0*exp(a1))*exp(a2/xi)In the a0*exp(a1) part, there's really only one parameter! Forexample, the solution a0=1, a1=1 is exactly equivalent to a solutionwith a0=e and a1=0. Nothing in this nonlinear regression will helpyou figure out whether a0 is really 1 or e. You might try rewritingyour model as yi=c1*exp(c2/xi)+c3*exp(c4/xi)+...Your nonlinear least squares problem is called a separable problem becausesome of the parameters occur linearly and some occur nonlinearly. There arespecial purpose algorithms for such problems that can help somewhat. SeeHans Bruun Nielsen's technical report at http://www.imm.dtu.dk/documents/ftp/tr00/tr01_00.abstract.html -- Brian Borchers borchers@nmt.eduDepartment of Mathematics http://www.nmt.edu/~borchers/Socorro, NM 87801 FAX: the model functions are > essentially of the form:> yi=a0*exp(a1+a2/xi) + a3*exp(a4+a5/xi) + .....> (This is the sum of a number of first order kinetics processes where > temperature (x) changes with time.)> The number of exp-terms is between 1 and 6 and the number of xi,yi is > between 64 and 256.> This problem is, at least in my case, very ill conditioned In fact it is singular, since you cannot estimate a0 and a1 separatelysince y depends only on the product a0*exp(a1); similarly for theother terms. Set a1=a4=0 to remove the redundancy, and things willbecome better. If problems remain, try adding to your least squareobjective a tiny multiple of a properly weighted sum of the squares ofyour parameters.But you cannot expect getting very good results since exponentialfitting problems are usually quite poorly posed. Which means thateven when you have a good fit, drawing conclusions about the Ôtrue'values of the parameters is dangerous - variances are governed bythe diagonal entries of the inverse Hessian at the solutionwhich tend to be $199.00.> Oh sorry, I was referring to the academic license which I believe is>> still free. > I searched on the intel website, but I could not find a free academic> license version for the MKL. Where would I find this, or has it been> discontinued?> UshnishNo way! you have to pay for it. So know a source for scheme implementations of nonlinear source for scheme implementations of nonlinear >optimization algorithms such as levenberg-marquardt ?? >what Ôs that? anyone have a formula to compute the balance on a mortgage formula to compute the balance on a mortgage loan> amortization after n payments?After i payments on an n-payment mortgage, there are n-i payments remaining.Hence, from the formula for the present value of an annuity, the principal Premaining after i payments of amount A isP=(A/r)[1-(1+r)^(-n+i)],where r is the interest rate per formula to compute the balance on a mortgage loan>> amortization after n payments?>> After i payments on an n-payment mortgage, there are n-i payments> remaining. Hence, from the formula for the present value of an> annuity, the principal P remaining after i payments of amount A is> P=(A/r)[1-(1+r)^(-n+i)],> where r is the interest rate per period (e.g., annual rate/12).Thus, the ratio R of the principal remaining after i payments to theoriginal principal always suggest using LAPACK (or CLAPACK if you prefer C) from www.netlib.org as opposed to anything from Numerical Recipes. Matlab matrix> computations (starting in Matlab 6.0) are performed using LAPACK. And> LAPACK is free!> John> I know about lapack and clapack, and I know they are high performance> libraries, but they are just so cumbersome. That's a pain, for > people who are not numerical-analysts, and only use these libraries> as black-boxes.> I actually write code in c++ and I know about lapack++, and I just > saw it was superseeded by TNT. That's nice, I thought, but then I > see they have their own implementation of 1D array, complex, etc. > Why do that, when there's already vector, valarray, and complex in> C++? > I do have the freedom to choose what routines I use, but is there> a C++ numerical library which combines the performance of lapack or> NR, with the elegance and convenience of C++? Also, one which does> not re-invent the wheel and which is free.It may be useful to look for the postings on comp.lang.c++ under thesubject Available C++ libraries by Nikki Locke.I agree with you that there does not seem to be any perfect solutionsfor matrix computations in C++ in the same way that LAPACK exists forFORTRAN (and C). I have developed my own class library whose primarygoal is to interface to the core functionality of LAPACK/ATLAS/IntelMKL while hiding the details of interfacing with these libraries. Ifyou're interested in seeing what I've got, I'm willing to CLAPACK if you prefer C) from> www.netlib.org as opposed to anything from Numerical Recipes. Matlabmatrix> computations (starting in Matlab 6.0) are performed using LAPACK. And> LAPACK is free!>> John>> I know about lapack and clapack, and I know they are high performance> libraries, but they are just so cumbersome. That's a pain, for> people who are not numerical-analysts, and only use these libraries> as black-boxes.>> I actually write code in c++ and I know about lapack++, and I just> saw it was superseeded by TNT. That's nice, I thought, but then I> see they have their own implementation of 1D array, complex, etc.> Why do that, when there's already vector, valarray, and complex in> C++?>> I do have the freedom to choose what routines I use, but is there> a C++ numerical library which combines the performance of lapack or> NR, with the elegance and convenience of C++? Also, one which does> not re-invent the wheel and which is free.>Silviu,I'm not sure what platform you're using, but if it's Windows/Visual Studio,then at least there are precompiled binaries of CLAPACK at netlib. Ifyou're on a Unix platform, the install procedure is fairly straightforward(though I understand what you mean by cumbersome). Once you've gonethrough the procedure once it really isn't all that bad, and you simplycannot beat the performance of CLAPACK for the price ($0.00).LAPACK++, as you've noted, is dead and has been replaced by TNT. I havemixed feelings about TNT, particularly the VERY slow pace of development andlack of real functionality. The focus of TNT these days seems to be onproviding better multi-dimensional array classes that Dr. Pozo believeswill help with portability and maintenance issues with C++ codes. I'm notan expert C++ programmer, so I cannot comment intelligently on how well TNTachieves its stated objectives.If you're digging around for C++ libraries, you might want to browse throughhttp://www.thefreecountry.com/sourcecode/ mathematics.shtmlThe Boost libraries seem to be popular these what platform you're using, but if it's Windows/Visual Studio,> then at least there are precompiled binaries of CLAPACK at netlib. If> you're on a Unix platform, the install procedure is fairly straightforward> (though I understand what you mean by cumbersome). Once you've gone> through the procedure once it really isn't all that bad, and you simply> cannot beat the performance of CLAPACK for the price ($0.00).and installation is trivial. What I find cumbersome in lapack isthe function prototypes and the row-column conversion of matrices.> If you're digging around for C++ libraries, you might want to browse through> http://www.thefreecountry.com/sourcecode/mathematics.shtml> The Boost libraries seem to be popular these days as well (www.boost.org).> (gsl). It looks more humane, although, being written in C, it mustimplement its own vector, complex, etc. I don't know how performant it is though. Any experience C++ libraries that are outthere.I do know that you have to be very careful when performance claims are madewith C++. For example, I believe Blitz++ claims _amazing_ performance, butonly for very specific processors/compilers.Your best bet is to check out several and find what works best for you.Actually, one of my primary gripes with C++ is the lack of built infunctionality to work with arrays (vectors/matrices/linear algebra). I'verun into exactly the same problems that you are encountering when it comesto finding good numerical linear algebra libraries, includingvector/matrix classes that can be made to work efficiently.IMHO, Fortran 90/95 is far better if a majority of your work is focused onthe field of numerical linear algebra. There is a nice Fortran 95 interfacefor LAPACK that simplifies the calling syntax considerably (provides ageneric interface for all LAPACK driver routines regardless of type andautomatically allocates temporary work arrays). I use it all the time andcouldn't be happier.>> I'm not sure what platform you're using, but if it's Windows/VisualStudio,> then at least there are precompiled binaries of CLAPACK at netlib. If> you're on a Unix platform, the install procedure is fairlystraightforward> (though I understand what you mean by cumbersome). Once you've gone> through the procedure once it really isn't all that bad, and you simply> cannot beat the performance of CLAPACK for the price ($0.00).>> and installation is trivial. What I find cumbersome in lapack is> the function prototypes and the row-column conversion of matrices.> If you're digging around for C++ libraries, you might want to browsethrough> http://www.thefreecountry.com/sourcecode/mathematics.shtml> The Boost libraries seem to be popular these days as well(www.boost.org).> (gsl). It looks more humane, although, being written in C, it must> implement its own vector, complex, etc. I don't know how performant> it is answers on my question. You are of course right with the a0, a1 correlation in:yi=a0*exp(a1+a2/xi) + a3*exp(a4+a5/xi) + .....This is, however due to me over simplifying the problem. My apologies for posing a seemingly trivial problem.It should have been:There are between 1 and 6, say k=1..m differential equations:dy1(x)/dx=-yk(x)*exp(a1-a2/x) with initial value x=x0 and y1(x0)=a0dy2(x)/dx=-yk(x)*exp(a4-a5/x) with initial value x=x0 and y2(x0)=a3.... etc (x is actually (a function of) temperature in time during heating of a sample)The model then is in quasi Mathematica notationYi=Sum[Integrate[dyk(x)/dx,{x,x0,xi}],{k,1,m}]for i=1..n, n>>mEach diffeqn results in a skew bell-shaped function resulting in a sum that has a bumpy bell shape.In practice the a1 is of the same size as a2/x and the final x is about 2*x0. This means that increasing both a1 and a2 makes no dramatic change and can easily be compensated by small changes in the parameters of an other of the diffeqns.So I thought that the solution could be in transforming a0,a1,a2 etc into other variables b0,b1,b2.... more or less along the lines of orthogonalisation in improving the stability of linear problems.Unfortunately, however, although I passed my exams numerical analysis 30 years ago, this is too complex for me to find out for my self. That's why I asked for help on the news group.The suggestion of adding a fraction of the sum of squares of the parameters as a kind of penalty to the ssq clearly improves the system. In addition it is even physically relevant because in particular the a1, a4 .. should not be too large to have a physical meaning.Janwillem van DijkNRG sample values taken from a bandlimited function.I assume that sampling has been done properly (nyquist criteria).I like to calculate the first derivative of this function by usingthe Derivative Theorem of the Fourier transform: df[n]/dt <=> -jnF[n]- First I do a Fourier transform. As I only have real values, the resulting function is hermitian: f(x) = f*(-x) f* means conjugate complex- Then the multiplication with -j (-sqrt(-1)) is a rotation of 90deg around the time axis. Easy saying: re_new = im_old im_new = -re_old- than I multiply the result values with their index n for example size 8: index: 0 1 2 3 4 5 6 7 factor 0 1 2 3 k -3 -2 -1 and there is the problem! what to do at index 4? in order to keep the hermitian property f(4)=f*(4) I would have to force the imaginary component to 0, but that would alter the data and therefore lead to a less precise results. The reason why I want to keep the hermitian property is, that I want a real function after the inverse Fourier transform. Fortunately this is only a problem when I have an even number of samples, so I can always zero pad to a odd number. But that is not very satisfying, and I would appreciate a cleaner solution.Maybe someone can help me out here!Martin