Module 4: Modular Programming

A pplying the concept of Modular Programming involves using a function created by someone else (the instructor, in this case), designing your own M-file script to use this function, as well as the other modules needed to complete the second programming assignment.

You can obtain your own copy of this module.

mkdir program2
cd program2
cp ~stewart/cs205/spr98/getinput.m .
cp ~stewart/cs205/spr98/testit.m .

Don't forget the final period (.) in the cp command above.

In Lab on Monday, I asked what would be the effect of placing a MATLAB whos command within getinput.m and within testit.m.

You should have begun the design of the two modules that this programming assignment requires you to write:

  1. runtruss.m (your MATLAB script file to coordinate the tasks, get user input by calling getinput.m, calling your MATLAB function file, setup.m, below to assemble the matrix A and the right hand side b, solve the linear system using the MATLAB matrix left division, and finally output your solution vector, x
  2. setup.m (your MATLAB function file which has 3 user provided input values for the Forces for the pin-joint truss and produces 2 output values, A and b)
I would like you to implement this in lab today. I recommend having an Xwindow open where you can edit your MATLAB source code (using pico) as well as another Xwindow open where you can run MATLAB itself. You need to remember to save the editted source code as you make changes. You will not need to quit the editor, but your changes are not written to the file until you save so rerunning MATLAB on your evolving script file won't reflect changes that are not saved.

The interplay between the Pico window and the MATLAB window is something that you need to become comfortable with very soon.

There is another way to use a single window and perform editting and MATLAB runs, alternatingly. This might also be useful for accessing MATLAB from home via a modem connection and a telnet program, if you have the luxury of having this capability.

Within the MATLAB window (>> prompt), you can issue commands to the Operating System by prefacing with the asterisk (!).

>>! pico runtruss.m

It's a personal choice whether alternating back and forth between two different windows - or using one window and alternating with application program you are using - is a natural environment for you.

Page author: Dr. Kris Stewart
URL: http://www.stewart.cs.sdsu.edu/cs205/module4/Apply.html
Last updated: Feb. 18, 1998