ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi users
I would like your help with converting this Matlab code to Fortran code.Im not familiar with Matlab.
thanks in advance.
[]
% make sure that the array with data that you have is a long one, correlation functions are need a lot of trajectories to become smooth.
file = fopen(DATA....);
Pxy = fscanf(file,'%f',[1 inf]);
% make an array with the final correlation function, choose NTimeSteps to be much smaller than the length of Pxy
NTimeSteps = round(tmax/dt);
ACF = zeros(1,NTimeSteps);
% start various evaluations of the correlation function from different (uncorrelated) times.
Shift = round(0.5/dt); % where '0.5' is approximately the time is takes for starting points to become uncorrelated, depending on your system
Ntraj = round((length(Pxy) - NTimeSteps)/Shift);
for j = 1 : Ntraj
for i = 1 : NTimeSteps
ACF(i) = ACF(i) + Pxy(1 + (j-1)*shift)*Pxy(i + (j-1)*shift); % (j-1) because Matlab won't allow starting a loop with j=0. But you might use a different language.
end
end
% ensemble averaging
ACF = ACF / Ntraj;
% integral over the correlation function
intACf = cumsum(ACF) / (V*k_B*T) * dt;
cumsum is not the most elegant integration method, you can also use simpson rule or something like that. I believe that would be 'quad' in Matlab.
Hi astrogeek
its not homework! any help will be appreciated.
Ok, I guess the place to start would be to ask what you have done so far.
I do not know matlab, but the expressions look understandable enough (although they do not look to be complete). Maybe it would help to know the source and target contexts. Where is this used?
!% (j-1) because Matlab won't allow starting a loop with j=0. But you might use a different language.
ACF(i) = ACF(i) + Pxy(1 + (j-1)*shift)*Pxy(i + (j-1)*shift)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.