Professional Documents
Culture Documents
Note Dualing
Note Dualing
Note Dualing
2016/2017
1 >> ver
2 --------------------- ver shows the Matlab version we
3 MATLAB Version: 8.0.0.783 (R2012b)
4 MATLAB License Number: 722761 are working on.
5 ....
1 >> pwd
pwd returns the name of the current
2 C :\ Programmi \ MATLAB \ R2006b \ work directory (in this example it is the
3 >> ls default directory)
4 . etc license . txt simulink ls returns the list of the files in the
5 .. extern notebook
current directory.
1 >> pi
2 ans =3.1416
Some real constants are allocated by 3 >> i
default: 4 ans =0+1 i
5 >> inf
6 ans = Inf
where
s is the sign: 0 (+) or 1 (-) ;
is the base system ;
e is the exponent : e [L, U], L < 0, U > 0 ;
m = a1 a2 ...at is the mantissa or fractional part.
The for loop repeats the instructions while the variable (counter) runs its values.
start and finish represent the first and the last values assumed by the counter,
step is the increment on the counter value at each repetition of the loop.
The while loop repeats the instructions while the logical condition is true.
If you unwillingly create an infinite loop (a loop that never ends on its own), stop
execution of the loop by pressing Ctrl + C.
The file name where the function is saved must be equal to that of the function:
function name.m.
The function comments are displayed upon typing
1 >> help function_name
2 comments
The variables defined internally to a function are deleted after the function
execution is returned to the main program (local variables) and only the output
variables are still defined.
MME - Lecture 1 - Aurelio Giancarlo Mauri
Example
produces values between x1 and xn with the increment given by step (same
syntax as the for loop);
1 >> y = linspace ( x1 , xn , N )
Example:
1 >> plot (x ,y , -- go , Markersize ,3 , Linewidth ,2)
Exercise 1.1
Let x=10. Compute:
exp(sin(x 2 )) + cos(x)
y=
2 x + 5 log(x)
Given a vector x with positive, negative and null entries, replace all negative
entries with zero.
Generate a magic square (M = magic(n), n being integer greater than 0) and
calculate the row and column sums.