Section 1.1 Matlab interface
The first thing you see in Matlab is its Command Window where the prompt >>
invites you to enter any command that will be executed at once. This window is useful for quickly trying out things. You should use it to try out the one-line examples that appear in the text of these notes.
Most of our work, including homework assignments, will involve Script Editor. To open this editor, click “New Script” button on the left of the “Home” menu of Matlab. The chain of commands entered in the editor forms a script. The button “Run” of the “Editor” menu runs a script; pressing F5 does the same.
The result of script computations can be shown in the Command Window. There are several ways to make it appear. One of them is disp
command: for example,
disp('Hello world')
displays "Hello world", and
disp(2/3)
displays 0.6667. Notice that Matlab displays just four digits after the decimal dot. This is intentional: showing fewer digits of each number makes is possible to fit more of them on the screen. There are ways to change the number format to display more digits, which we will consider later.
Example 1.1.1. Golden ratio.
Write a script that displays an approximate decimal value of the golden ratio \(\dfrac{\sqrt{5}+1}{2}\text{.}\)
disp((sqrt(5)+1)/2)