Scripts are the simplest way to write programs in MATLAB. Though they have limitations, they are easy to write and easy to extend. The presentation here is meant to help you start writing script Mfiles in MATLAB. Feel free to extend, alter or otherwise improve on this prescription.
Steps in the process:
The computer is an excellent calculation tool but it does not know what to do to solve problems until you direct it. It is very unusual for someone to just sit down and get results. Some level of preparation and thought is required before using the computer.
Some questions to answer before you start:
You've decided how
to solve it and (importantly) that the computer is an effective means to
implementing the solution. If the solution is more than a few lines of
MATLAB code, using just the command line is not going to be very efficient.
You'll need to create a script that allows you to develop the code for the
algorithm. In addition, the script will record your work, and make it
plain what your problem-solving strategy is.
Here are some things you should do to ensure a reliable set-up of a MATLAB
script
Set up what you know about the problem, remembering that your algorithm should determine the results based on the "givens" alone. If that is not possible, re- evaluate your algorithm.
Some items that might be set before any calculations are carried out.
MATLAB is ready, you are ready. Time to turn your algorithm (or solution procedure) into hard code. Beware: this is not likely to be a one-shot, linear process. You will have to try things, make errors, correct errors and perhaps even modify your algorithm. Give yourself time and patience.
Some issues to remember when coding in MATLAB
The point of solving a problem is to get some results that will give you some insight into the issues you are working on. A typical reason for using the computer is to use the graphical capabilities of the computer to produce plots or other graphic elements. Results should be displayed in meaningful and informative ways to maximize the value of your effort.
Computer output and results can take many forms:
In solving a problem, new ideas and problems come up. Some of them can be very interesting and creative. Some can help you develop a better understanding of your problem. Some can help you improve your problem-solution strategy. Evaluate your results, consider them and maybe ask a "What if?" question.