CoCalc -- Collaborative Calculation in the Cloud
Sharedsupport / 2016-02-23-matlab.htmlOpen in CoCalc

Examples for support purposes...

2016-02-23-matlab
In [3]:
a = [1 2 3 4 6 4 3 4 5]
Out[3]:
a =

   1   2   3   4   6   4   3   4   5

In [4]:
b = a + 2
Out[4]:
b =

   3   4   5   6   8   6   5   6   7

In [5]:
plot(b)
grid on
Gnuplot Produced by GNUPLOT 4.6 patchlevel 6 3 4 5 6 7 8 0 2 4 6 8 10 gnuplot_plot_1a
Out[5]:
In [6]:
bar(b)
xlabel('Sample #')
ylabel('Pounds')
Gnuplot Produced by GNUPLOT 4.6 patchlevel 6 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 Pounds Sample # gnuplot_plot_1a gnuplot_plot_2a gnuplot_plot_3a gnuplot_plot_4a gnuplot_plot_5a gnuplot_plot_6a gnuplot_plot_7a gnuplot_plot_8a gnuplot_plot_9a gnuplot_plot_10a gnuplot_plot_11a gnuplot_plot_12a gnuplot_plot_13a gnuplot_plot_14a gnuplot_plot_15a gnuplot_plot_16a gnuplot_plot_17a gnuplot_plot_18a gnuplot_plot_19a
Out[6]:
In [7]:
plot(b,'*')
axis([0 10 0 10])
Gnuplot Produced by GNUPLOT 4.6 patchlevel 6 0 2 4 6 8 10 0 2 4 6 8 10 gnuplot_plot_1a
Out[7]:
In [8]:
A = [1 2 0; 2 5 -1; 4 10 -1]
Out[8]:
A =

    1    2    0
    2    5   -1
    4   10   -1

In [9]:
B = A'
Out[9]:
B =

    1    2    4
    2    5   10
    0   -1   -1

In [10]:
C = A * B
Out[10]:
C =

     5    12    24
    12    30    59
    24    59   117

In [11]:
C = A .* B
Out[11]:
C =

    1    4    0
    4   25  -10
    0  -10    1

In [12]:
b = [1;3;5]
x = A\b
Out[12]:
b =

   1
   3
   5

x =

   1
  -0
  -1

In [13]:
r = A*x - b
Out[13]:
r =

   0
   0
   0

In [14]:
eig(A)
Out[14]:
ans =

   3.73205
   0.26795
   1.00000

In [15]:
svd(A)
Out[15]:
ans =

   12.31706
    0.51490
    0.15768

In [16]:
p = round(poly(A))
Out[16]:
p =

   1  -5   5  -1

In [17]:
roots(p)
Out[17]:
ans =

   3.73205
   1.00000
   0.26795

In [18]:
q = conv(p,p)
Out[18]:
q =

    1  -10   35  -52   35  -10    1

In [19]:
r = conv(p,q)
plot(r);
Gnuplot Produced by GNUPLOT 4.6 patchlevel 6 -600 -400 -200 0 200 400 600 0 2 4 6 8 10 gnuplot_plot_1a
Out[19]:
r =

     1   -15    90  -278   480  -480   278   -90    15    -1

In [20]:
whos
Out[20]:
Variables in the current scope:

   Attr Name             Size                     Bytes  Class
   ==== ====             ====                     =====  ===== 
        A                3x3                         72  double
        B                3x3                         72  double
        C                3x3                         72  double
        _fig             1x1                          8  double
        _figHandles      1x1                          8  double
        _filename        1x27                        27  char
        _handle          1x1                          8  double
        a                1x9                         72  double
        ans              3x1                         24  double
        b                3x1                         24  double
        p                1x4                         32  double
        q                1x7                         56  double
        r                1x10                        80  double
        theta            1x6284                      24  double
        x                3x1                         24  double

Total is 6380 elements using 603 bytes

In [21]:
A
Out[21]:
A =

    1    2    0
    2    5   -1
    4   10   -1

In [22]:
sqrt(-1)
Out[22]:
ans =  0 + 1i
In [ ]: