Download Computational Mechanics featuring Matlab

Transcript
14
CHAPTER 1. HELLO WORLD!
1.12
Review of commands introduced in this chapter
For more information on each command type >>help cmdname at the Matlab
command line.
cos() Cosine of argument in radians.
disp() disp(X) displays variable X without printing its name. Otherwise it is
same as leaving the semicolon off and typing X. If X is a string, the text is
displayed.
input() Prompt for user input.
fprintf() Write formatted data to text file.
%s, %d, %e, %i Formatting strings. Strangely, Matlab help refers you to a C
manual for these.
strings Character strings, arrays of text (help strings).
log() Natural logarithm.
+, -, *, /, ^ Arithmetic operators (help arith).
types of numbers Matlab has integers, floats, and strings, (and variations on
these)(help datatypes).
1.13
End of Chapter Problems
(1) The universe is about 15 billion years old. The radius of the observed universe is 15 billion light-years. Using this fact and the observation that
there are only about one million atoms in every cubic meter of space (on
average), write a script to calculate the total number of atoms in the universe. Use a fprintf() statement to give your numerical answer with a
complete sentence. [The result of this calculation, by the way, is about the
largest possible number that represents a number of objects. There are
many larger numbers used in mathematics and science, but they represent
ideas or probabilities, not real things.]
(2) In England and Ireland people still give their weight in “stones”. Write an
interactive script that asks you your weight in pounds and tells you your
weight in stones.
(3) Write an interactive script that first asks you the speed of a projectile, then
the launch angle in degrees, and returns to you the x and y components of
the velocity, as follows:
Launch angle = 30◦ , speed=10 m/s, vx= 8.6 m/s, vy=5 m/s