The Attempt at a Solution
I'm taking Computational Physics. And I am trying to learn how to program in matlab. But I don't understand the author's code and what it is in matlab code. Can someone help me?
It is True BASICDo you know what language that is? It looks somewhat, but not quite, like FORTRAN to me. The code for the subroutines 'initialize', 'calculate', and 'display'. are missing. So there is practically no details there about what the program does. Are you talking about converting the entire thing to MATLAB or just this top level program that calls the subroutines?
[n_uranium, t] = initialize(tau, dt);
[n_uranium, t, tau, dt] = initialize();
Yes. All three of those called functions are specialized code just for that model. They are not general utilities that are part of the language. You will need to find the code for them and translate them to MATLAB also. You are probably only looking at the tip of the iceberg in the code you have posted.are you saying initialization is some other program/function that is being called up?
Yes. All three of those called functions are specialized code just for that model. They are not general utilities that are part of the language. You will need to find the code for them and translate them to MATLAB also. You are probably only looking at the tip of the iceberg in the code you have posted.
Everything there is fairly easy to do in MATLAB unless you want to exactly mimic the graphing and display part. MATLAB has very good graphing capability of its own but it will not look exactly the same. MATLAB is very powerful and popular (within Physics and Engineering), so unless you already know other languages, it would be a good one to use. It's not free. Do you have MATLAB available to use?
Discuss that with your teacher. If she would be happy with the MATLAB type of graph, then I recommend using MATLAB.
Otherwise, it is very difficult to use one utility to exactly mimic another utility. It could be a real effort for a professional programmer. If she really wants an exact match, then you would need to use the code you have. If the functions settitle, sethlabel, setvlabel, and datagraph in the display part are specialized code, you would need to find that and use it. If they are in a utility library, you would need to use that.
I use True BASIC routinely, and that is indeed what this code is. It is a very powerful, flexible, and easy to use language. When my last employer required everything to be done in Matlab, I would first get it running in True BASIC, and then convert to Matlab, a great waste of effort, but easier for me than working in Matlab.
View attachment 220271
The main program is the first 10 lines, down to the END statement. There are three external subroutines called INITIALIZE, CALCULATE, AND DISPLAY. The calling arguments for each are shown in the main program, and they correspond one-to-one to the lists in the subroutine declarations, even through the names are different. Thus, the first calling argument in the call to INITIALIZE is n_uraniaum which was previously dimensioned 100 in the main program. In the subroutine, the first argument is NUCLEI() where the parenthese tell the code to exxpect a one dimensional array.
The easiest way to run this code is to download the free trial version of True BASIC Bronze edition from TrueBASIC.com.
My understanding is that True BASIC will run with no modifications on either Windows or a Mac. Check the web site to be sure. That was always one of their selling points. I've been using this software for over 30 years for teaching, consulting, and research, and I have nothing but praise for it. It is not fast enough to serve for robotics applications (real time control), but for everything else, I have found it to work great. I've written fairly large programs (a few thousand lines) and little short programs, and everything works just like I expect it to.
In the code itself is the lineThe original program includes a (less than helpful) comment that says about sgfunc and sglib that they are found "here" wherever that is. Without them, you don't have the whole program.
library "sgfunc*", "sglib*"