---------------------------------------------------
 
-x_1 +  x_2 + 2x_3 = 10
3x_1 -  x_2 + x_3 = -20
-x_1 + 3x_2 + 4x_3 = 40
 
A=[-1 1 2;3 -1 1;-1 3 4]
 
A*[x_1;X_2;x_3]=[10;-20;40]
 
Check det(A) is not 0.
[x_1;X_2;x_3]=inv(A)*[10;-20;40]
b=[10;-20;40]
 
>x=inv(A)*b' or
>x=A\b' (Gaussian Elimenation)
 
 
>ones(3,2)
>eye(3,3)
>eye(3)
>eye(3,2)
>ones(3,2)+eye(3,2)
 
 
>diag([2 4 5])
e-values are 2 4 5.
 
A and b are given above.
 
>F=[Ab']
>G=rref(F) --->give solution
>rrefmovie(F)
 
 e-value
det(B-\labbda*I)=0
 
>D=diag([1 2 3])
>eig(D) 
 
>P=[1 2 3;4 5 6;5 7 8]
>B=inv(P)*A*P
>eig(B)
 
* eig(D)=eig(B)
 
 complex nbr i,j
>angle()
>abs()
>real()
>imag(b)
>conj(b)=b'
>exp(i*pi)
 
>x=-3:3
>abs(x)>1
>y=x(abs(x)>1)
 
>x=-3:3
>find(x>2)
 
-----------------------------------------------------
 
>gcd(69,15)
>rem(7,2)  --->remainder
>floor(7/2) -->quotient
 
----------------------------------------------
>> A=1:9
>> B=9-A
>>tf=A>A
>>tf=(A==B)
>> tf=B-(A>2)
>> x=(-3:3)/3
 
>>A=1:9
>> B=9-A
>> tf=A>4
>> tf=~(A>4)
>> tf=(A>2)&(A<6)
 
>> D=[2 1 3 4 7]
 
>>min(D)
>>median(D)
>>prod(D)
>>sum(D)
>>cumsum(D)
>>std(D) %std deviation
>>sort(D)
 
 
>>clf
>>hist(D,3) ---->figure1
>>figure
>>hist(D)   ---->figure2
 
>> y=hist(D,3)
>>y
>>[y x]=hist(D,3) %x:midpoint
>>hist(D,3)
>>bar(x,y)
 
 
%Scatter plot and ...
 
>>tomato--->run tomato.m
>>plot(x,y,'r*')
 
>>[sx k]=sort(x)
>>sy=y(k)
>>plot(sx,sy)
 
-------------------------------------------
 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%      Least Square       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
% (1) Y = alpha + beta*x = AC
% (2) Y = alpha + beta*x + gamma*x^2 =AC
 
 
 
x=[2 6 4 8 12 10 18 0 16 14]';
y=[4.70 4.84 5.02 5.38 5.47 5.61 5.95 4.01 5.90 5.80]';
[x y]
 
x=[2 6 4 8 12 10 18 0 16 14]';
y=[4.70 4.84 5.02 5.38 5.47 5.61 5.95 4.01 5.90 5.80]';
[x y]
 
ans =
 
    2.0000    4.7000
    6.0000    4.8400
    4.0000    5.0200
    8.0000    5.3800
   12.0000    5.4700
   10.0000    5.6100
   18.0000    5.9500
         0    4.0100
   16.0000    5.9000
   14.0000    5.8000
 
A=[ones(size(x)) x]
 
A =
 
     1     2
     1     6
     1     4
     1     8
     1    12
     1    10
     1    18
     1     0
     1    16
     1    14
 
c = A\y
 
c =
 
    4.3985
    0.0966
 
alpha =c(1)
 
alpha =
 
    4.3985
 
beta = c(2)
 
beta =
 
    0.0966
 
Y= alpha +beta*x
 
Y =
 
    4.5918
    4.9782
    4.7850
    5.1714
    5.5578
    5.3646
    6.1375
    4.3985
    5.9442
    5.7510
 
clc
[x y Y]
 
ans =
 
    2.0000    4.7000    4.5918
    6.0000    4.8400    4.9782
    4.0000    5.0200    4.7850
    8.0000    5.3800    5.1714
   12.0000    5.4700    5.5578
   10.0000    5.6100    5.3646
   18.0000    5.9500    6.1375
         0    4.0100    4.3985
   16.0000    5.9000    5.9442
   14.0000    5.8000    5.7510
 
plot(x,y,'r*')
hold on
plot(x,Y,'g')
r= y-Y
 
r =
 
    0.1082
   -0.1382
    0.2350
    0.2086
   -0.0878
    0.2454
   -0.1875
   -0.3885
   -0.0442
    0.0490
 
R2 = r'*r
 
R2 =
 
    0.3880
 
fschange('/home/elee/mymatlab/tomato.m');
clear tomato
clc
[x y]
 
ans =
 
    2.0000    4.7000
    6.0000    4.8400
    4.0000    5.0200
    8.0000    5.3800
   12.0000    5.4700
   10.0000    5.6100
   18.0000    5.9500
         0    4.0100
   16.0000    5.9000
   14.0000    5.8000
 
A=[ones(size(x)) x x.^2]
 
A =
 
     1     2     4
     1     6    36
     1     4    16
     1     8    64
     1    12   144
     1    10   100
     1    18   324
     1     0     0
     1    16   256
     1    14   196
 
c=A\y
 
c =
 
    4.1826
    0.1776
   -0.0045
 
alpha =c(1)
 
alpha =
 
    4.1826
 
beta =c(2)
 
beta =
 
    0.1776
 
gamma =c(3)
 
gamma =
 
   -0.0045
 
plot(x,y, 'r*')
plot(x,y,'r*')
hold on
plot(x,Y,'g')
Y= alpha + beta*x +gamma
 
Y =
 
    4.5333
    5.2436
    4.8884
    5.5987
    6.3090
    5.9539
    7.3744
    4.1781
    7.0193
    6.6641
 
fschange('/home/elee/mymatlab/tomato.m');
clear tomato
Y= alpha + beta*x +gamma*x.^2
 
Y =
 
    4.5198
    5.0861
    4.8210
    5.3153
    5.6658
    5.5085
    5.9215
    4.1826
    5.8723
    5.7870
 
plot(x,y,'r*')
plot(x,y,'r*')
hold on
plot(x,Y,'g')
 
---------------------------------------------------------------
 
%Polynomial
>> p = [1 -2 0 25 116]; --->x^4 - 2x^3 + 25x + 116
>> r = roots(p)
 
r =
 
   2.9832 + 2.7986i
   2.9832 - 2.7986i
  -1.9832 + 1.7320i
  -1.9832 - 1.7320i
 
>> pp = poly(r)
 
pp =
 
    1.0000   -2.0000    0.0000   25.0000  116.0000
 
 
>> a=[1 2 3 4] --->a(x)=x^3 + 2x^2 + 3x +4
 
a =
 
     1     2     3     4
 
>> b=[1 4 9 6]
 
b =
 
     1     4     9     6
 
>> c=conv(a,b)  %convolution (multiplication of two polys
 
c =
 
     1     6    20    40    55    54    24  --->6 degree polynomial
 
>> d=a+b
 
d =
 
     2     6    12    10
 
>> e=c+[0 0 0 d]
 
e =
 
     1     6    20    42    61    66    34
 
polyadd(c,d)
 
ans =
 
     1     6    20    52    81    96    84
 
[q, r] =deconv(c,b)
 
q =
 
     1     2     3     4
 
 
r =
 
     0     0     0     0     0     0     0
 
g=[1 6 20 48 69 72 44]
 
g =
 
     1     6    20    48    69    72    44
 
h=polyder(g)
 
h =
 
     6    30    80   144   138    72
 
x=linspace(-1,3)
 
x =
 
  Columns 1 through 6 
 
   -1.0000   -0.9596   -0.9192   -0.8788   -0.8384   -0.7980
 
  Columns 7 through 12 
 
   -0.7576   -0.7172   -0.6768   -0.6364   -0.5960   -0.5556
 
 
   ......... 
 
  Columns 91 through 96 
 
    2.6364    2.6768    2.7172    2.7576    2.7980    2.8384
 
  Columns 97 through 100 
 
    2.8788    2.9192    2.9596    3.0000
 
help linspace
 
 LINSPACE Linearly spaced vector.
    LINSPACE(x1, x2) generates a row vector of 100 linearly
    equally spaced points between x1 and x2.
 
    LINSPACE(x1, x2, N) generates N points between x1 and x2.
 
    See also LOGSPACE, :.
 
 
linspace(1,3,4)
 
ans =
 
    1.0000    1.6667    2.3333    3.0000
 
x=linspace(-1,3);
p=[1 4 -7 -10];
v=polyval(p,x);
plot(x,v)
title('x^3 + 4 x^2 - 7x + 10')
 
--------------------------------------------------
%n(x)/d(x)
 
>> n=[1 -10 100]
 
n =
 
     1   -10   100
 
>> d=[1 10 100 0]
 
d =
 
     1    10   100     0
 
>> z = roots(n)
 
z =
 
   5.0000 + 8.6603i
   5.0000 - 8.6603i
 
>> p = roots(d)
 
p =
 
        0          
  -5.0000 + 8.6603i
  -5.0000 - 8.6603i
 
>> [nn, dd] = polyder(n,d)
 
nn =
 
  Columns 1 through 3 
 
          -1          20        -100
 
  Columns 4 through 5 
 
       -2000      -10000
 
%i.e, -x^4 + 20x^3 - 100x^2 -2000x -10000
 
dd =
 
  Columns 1 through 3 
 
           1          20         300
 
  Columns 4 through 6 
 
        2000       10000           0
 
  Column 7 
 
           0
 
 
>> [r,p,k]=residue(n,d)
 
r =
 
   0.0000 + 1.1547i
   0.0000 - 1.1547i
   1.0000          
 
 
p =
 
  -5.0000 + 8.6603i
  -5.0000 - 8.6603i
        0          
 
 
k =
 
     []
 
------------------------------------------------------------
 
x=[2 6 4 8 12 10 18 0 16 14]';
y=[4.70 4.84 5.02 5.38 5.47 5.61 5.95 4.01 5.90 5.80]';
 
 
x
 
x =
 
     2
     6
     4
     8
    12
    10
    18
     0
    16
    14
 
y
 
y =
 
    4.7000
    4.8400
    5.0200
    5.3800
    5.4700
    5.6100
    5.9500
    4.0100
    5.9000
    5.8000
 
x=1:10
 
x =
 
     1     2     3     4     5     6     7     8     9    10
 
 
y=x.^3
 
y =
 
  Columns 1 through 5 
 
           1           8          27          64         125
 
  Columns 6 through 10 
 
         216         343         512         729        1000
 
polyfit(x,y,1)
 
ans =
 
  105.4000 -277.2000
 
xi=linspace(1,10);
fschange('/home/elee/mymatlab/polynomial_fit.m');
clear polynomial_fit
polynomial_fit
??? Error: File: /home/elee/mymatlab/polynomial_fit.m Line: 6 Column: 7
Missing operator, comma, or semicolon.
 
fschange('/home/elee/mymatlab/polynomial_fit.m');
clear polynomial_fit
polynomial_fit
 
x =
 
     1     2     3     4     5     6     7     8     9    10
 
 
p =
 
  105.4000 -277.2000
 
fschange('/home/elee/mymatlab/polynomial_fit.m');
clear polynomial_fit
polynomial_fit
 
x =
 
     1     2     3     4     5     6     7     8     9    10
 
 
p =
 
  105.4000 -277.2000
 
 
p =
 
   16.5000  -76.1000   85.8000
 
??? Error using ==> plot
String argument is an unknown option.
 
Error in ==> /home/elee/mymatlab/polynomial_fit.m
On line 19  ==> plot(x,y,'-o',xi,y_linear,'r:',y_quadratic,'m--')
 
fschange('/home/elee/mymatlab/polynomial_fit.m');
clear polynomial_fit
polynomial_fit
 
x =
 
     1     2     3     4     5     6     7     8     9    10
 
 
p =
 
  105.4000 -277.2000
 
 
p =
 
   16.5000  -76.1000   85.8000
 
----------------------------------------------
 
rand ---> Unif(0,1)
randn ---> Std Normal
>> rand
 
ans =
 
    0.5681
 
>> rand(2,3)
 
ans =
 
    0.3704    0.5466    0.6946
    0.7027    0.4449    0.6213
 
>> rand(2)
 
ans =
 
    0.7948    0.5226
    0.9568    0.8801
 
>> rand('seed',13)
>> b=rand(2,1)
 
b =
 
    0.6678
    0.9863
 
>> rand('seed',0)
>> a=rand(3,2)
 
a =
 
    0.2190    0.6793
    0.0470    0.9347
    0.6789    0.3835
 
>> rand('seed',13)
>> c=rand(2,1)
 
c =
 
    0.6678
    0.9863
 
>> x=rand(1,3)
 
x =
 
    0.6143    0.7985    0.6083
 
 
>> a=12;b=99;
>> y=a+(b-a)*x
 
y =
 
   65.4454   81.4655   64.9230
 
>> ceil(1.2)
 
ans =
 
     2
 
>> ceil(1.9)
 
ans =
 
     2
 
>> ceil(0.9)
 
ans =
 
     1
 
>> floor(1.2)
 
ans =
 
     1
 
>> floor(1.9)
 
ans =
 
     1
 
>> floor(0.6)
 
ans =
 
     0
 
>> round(1.2)
 
ans =
 
     1
 
>> round(1.5)
 
ans =
 
     2
 
>> round(1.9)
 
ans =
 
     2
 
>> 
>> 
>> x=rand(3,1)
 
x =
 
    0.8651
    0.4474
    0.6907
 
**** Create random integer
 
>> floor(6*x)
 
ans =
 
     5
     2
     4
 
>> floor(9.98)
 
ans =
 
     9
 
>> ceil(6*x)
 
ans =
 
     6
     3
     5
 
>> x=rand(1,10)
 
x =
 
  Columns 1 through 7 
 
    0.3742    0.2525    0.1195    0.1134    0.4568    0.1440    0.0305
 
  Columns 8 through 10 
 
    0.1401    0.9484    0.2173
 
>> floor(6*x)
 
ans =
 
     2     1     0     0     2     0     0     0     5     1
 
>> ceil(6*x)
 
ans =
 
     3     2     1     1     3     1     1     1     6     2
 
>> r=randperm(9)
 
r =
 
     5     8     4     3     1     7     2     6     9
 
--------------------------------
exprand
 
 % exprand.m
 % Task: Compute a matrix of size n x m, exponentially distributed with mean = mu
 % Usage: V = exprand(mu) % for 1 x 1
 %        V = exprand(mu,n) % for n x n
 %        V = exprand(mu,n,m) % for n x m
 
exprand(2)
 
ans =
 
    3.8706
 
exprand(2,4,5)
 
ans =
 
    0.9987    0.6653    0.7397    0.1090    0.5346
    0.6908    0.4728    5.4059    0.9735    4.5242
    2.0226    1.1213    3.2577    0.0133    4.0404
    1.2826    2.7186    0.6252    1.0982    4.0458
 
fschange('/home/elee/mymatlab/compare_distribution.m');
clear compare_distribution
fschange('/home/elee/mymatlab/compare_distribution.m');
clear compare_distribution
compare_distribution
fschange('/home/elee/mymatlab/compare_distribution.m');
clear compare_distribution
fschange('/home/elee/mymatlab/compare_distribution.m');
clear compare_distribution
compare_distribution
fschange('/home/elee/mymatlab/compare_distribution.m');
clear compare_distribution
fschange('/home/elee/mymatlab/compare_distribution.m');
clear compare_distribution
fschange('/home/elee/mymatlab/compare_distribution.m');
clear compare_distribution
compare_distribution
clear
m=180/131;
rand('seed',0)
z=exprand(m,50,1)
 
z =
 
    0.3396
    0.0662
    1.5608
    1.5626
    3.7493
    0.6646
    1.0068
    2.4426
    0.0483
    0.0755
    1.0366
    1.5281
    0.0106
    0.6644
    0.0951
    0.7425
    1.5950
    1.2217
    3.6625
    2.5721
    1.0285
    0.1326
    1.4580
    0.7390
    1.6598
    3.3135
    1.9736
    0.4183
    0.0668
    1.8304
    0.5467
    1.3760
    1.9405
    6.4782
    0.6247
    0.3899
    5.5627
    1.7622
    1.9234
    1.4485
    0.1037
    1.3722
    2.9683
    0.4375
    0.7879
    1.9986
    0.8925
    0.3731
    0.4417
    0.6116
 
t=cumsum(z)
 
t =
 
    0.3396
    0.4058
    1.9665
    3.5292
    7.2785
    7.9431
    8.9499
   11.3925
   11.4408
   11.5163
   12.5529
   14.0810
   14.0917
   14.7561
   14.8512
   15.5937
   17.1887
   18.4104
   22.0729
   24.6450
   25.6735
   25.8060
   27.2640
   28.0030
   29.6628
   32.9764
   34.9499
   35.3682
   35.4350
   37.2654
   37.8121
   39.1881
   41.1286
   47.6068
   48.2315
   48.6214
   54.1841
   55.9464
   57.8698
   59.3182
   59.4219
   60.7942
   63.7625
   64.2000
   64.9879
   66.9866
   67.8791
   68.2522
   68.6939
   69.3055
 
 
 
 
---------------------------------
 
 
 
x=linspace(0,2*pi,30)
y=sin(x)
z=cos(x)
plot(x,y,x,z)
grid on
grid off
box on 
box off
gtext('cos(x)')
text(2.5,0.7,'sin(x)')
legend('sin(x)','cos(x)')
axis([1 6.3 -0.8 0.8])
axis square
axis ij
axis auto
axis equal
 
 
a=[0.5 1.0 1.6 1.2 0.8 2.1]
pie(a)
pie(a,a==max(a))
pareto(a)
 
x=-2*pi:pi/10:2*pi
y=sin(x);
z=2*cos(x);
subplot(2,1,1)
plot(x,y,x,z)
title('two plots on the same scale')
subplot(2,1,2)
plotyy(x,y,x,z)
title('two plots on the different scale')
 
 
t=linspace(0,10*pi);
x=sin(t);
y=cos(t);
plot3(x,y,t)
 
 
---------------------------------------------
 
 
sym(1/3,'d') -->d: decimal
 
x=sym('x')
>> diff(cos(x))
 
ans =
 
-sin(x)
 
>> int(cos(x))
 
ans =
 
sin(x)
 
>> syms('a','b','c','d')
>> M=[a b ;c d]
 
M =
 
[ a, b]
[ c, d]
 
>> det(M)
 
ans =
 
a*d-b*c
 
>> syms a s t u omega ij
>> findsym(a*t + s/(u+3),1)
 
ans =
 
u    ---->matlab think of u as a variable(default)
 
>> findsym(sin(a+omega),1)
 
ans =
 
omega
 
>> syms a b c d x
>> f=a*x^2 + b*x +c
 
f =
 
a*x^2+b*x+c
 
>> g_prime=diff(sqrt(3*x^2 + 2*x +5))
 
g_prime =
 
1/2/(3*x^2+2*x+5)^(1/2)*(6*x+2)
 
>> sym s
 
ans =
 
s
>> h = (3*s^2 + 4*s + 2)/(5*s+7)
 
h =
 
(3*s^2+4*s+2)/(5*s+7)
 
>> int(h)
 
ans =
 
3/10*s^2-1/25*s+57/125*log(125*s+175)
 
 
>>x=sym('x')
 
>> M=[3*sin(t) -cos(t^2);4*t+1 exp(-2*t)]
 
M =
 
[  3*sin(t), -cos(t^2)]
[     4*t+1, exp(-2*t)]
 
>> det(M)
 
ans =
 
3*sin(t)*exp(-2*t)+4*cos(t^2)*t+cos(t^2)
 
>> syms a b x 
>> m=x^2
 
m =
 
x^2
 
>> [n,d]=numden(m)----> n:numerator, d:denominator
 
n =
 
x^2
 
 
d =
 
1
 >> h=(x^2 +3)/(2*x-1) +x/(x-1)
 
h =
 
(x^2+3)/(2*x-1)+x/(x-1)
 
>> [n,d]=numden(h)
 
n =
 
x^3+x^2+2*x-3
 
 
d =
 
(2*x-1)*(x-1)
 
>> M=[3/2,(2*x+1)/3;4/x^2, 3*x+1]
 
M =
 
[       3/2, 2/3*x+1/3]
[     4/x^2,     3*x+1]
 
>> [n,d]=numden(M)
 
n =
 
[     3, 2*x+1]
[     4, 3*x+1]
 
 
d =
 
[   2,   3]
[ x^2,   1]
 
M=n/d  or n./d
 
>> syms x u v
>> f=1/(1+x^2)
 
f =
 
1/(1+x^2)
 
>> g=sin(x)
 
g =
 
sin(x)
 
>> compose(f,g)
 
ans =
 
1/(1+sin(x)^2)
 
>> syms x a b
>> finverse(x^2)
Warning: finverse(x^2) is not unique.
> In /usr/local/share/matlab60/toolbox/symbolic/@sym/finverse.m at line 43
 
ans =
 
x^(1/2)
 
>> syms c d 
>> f=a*b + c*d -a*c
 
f =
 
a*b+c*d-a*c
 
>> finverse(f,a)
 
ans =
 
(-c*d+a)/(b-c)
 
>> diff(f,a)
 
ans =
 
b-c
 
>> syms x n
>> symsum((2*n-1)^2,1,n)---->sum of 2*n-1)^2 running 1 to n
>> factor(ans)
 
ans =
 
1/3*n*(2*n-1)*(2*n+1)
 
>> phi=sym('(1+sqrt(5))/2')
 
phi =
 
(1+sqrt(5))/2
 
>> double(phi)
and =
    1.6180
 
>> x=sym('x');
>> f=x^3 + 2*x^2 - 3*x +5
 
f =
 
x^3+2*x^2-3*x+5
 
>> n=sym2poly(f)
 
n =
 
     1     2    -3     5
 
>> poly2sym(n)
 
ans =
 
x^3+2*x^2-3*x+5
 
 
>> syms a alpha b c s x
>> f=a*x^2 + b*x + c
 
f =
 
a*x^2+b*x+c
 
>> subs(f,x,s)
 
ans =
 
a*s^2+b*s+c
 
>> subs(f,a,[alpha;s])
 
ans =
 
[ alpha*x^2+b*x+c]
[     s*x^2+b*x+c]
 
>> g=3*x^2 + 5*x - 4
 
g =
 
3*x^2+5*x-4
 
>> h=subs(g,x,2)     !!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
h =
 
    18
 
>>sym a x b c d
>>t = solve(a*x^3 + b*x^2 + c*x + d)
>> r=subexpr(t(2))
 
 
>> syms a b c d x s
>> f=a*x^3 + x^2 - b*x -c
 
f =
 
a*x^3+x^2-b*x-c
 
>> diff(f)
 
ans =
 
3*a*x^2+2*x-b
 
>> diff(f,a)
 
ans =
 
x^3
>> diff(f,2) ----->2nd derivative
 
ans =
 
6*a*x+2
 
>> diff(f,a,2)
 
ans =
 
0
 
F=[a*x,b*x^2;c*x^3,d*s]
 
F =
 
[   a*x, b*x^2]
[ c*x^3,   d*s]
 
diff(F)
 
ans =
 
[       a,   2*b*x]
[ 3*c*x^2,       0]
 
M=[(1:8).^2]
 
M =
 
     1     4     9    16    25    36    49    64
 
diff(M)
 
ans =
 
     3     5     7     9    11    13    15
 
x=sym('x')
 
x =
 
x
 
p=int(log(x)/exp(x^2))
Warning: Explicit integral could not be found.
> In /usr/local/share/matlab60/toolbox/symbolic/@sym/int.m at line 58
 
p =
 
int(log(x)/exp(x^2),x)
 
F=[1 2]
 
F =
 
     1     2
 
diff(F)
 
ans =
 
     1
 
syms x s m n
f=sin(s+2*x)
 
f =
 
sin(s+2*x)
 
int(f)
 
ans =
 
-1/2*cos(s+2*x)
 
int(f,s)
 
ans =
 
-cos(s+2*x)
 
int(f,pi/2,pi)
 
ans =
 
-cos(s)
 
int(f,s,pi/2,pi)
 
ans =
 
2*cos(x)^2-1-2*sin(x)*cos(x)
 
F=[1 2 4]
 
F =
 
     1     2     4
 
diff(F)
 
ans =
 
     1     2
 
clear
t=sym('t')
 
t =
 
t
 
digits(5)
a = sym('-9.7536')
 
a =
 
-9.7536
 
v=int(a,t)
 
v =
 
-9.7536*t
 
v=v+20
 
v =
 
-9.7536*t+20
 
y=int(v,t)
 
y =
 
-4.8768*t^2+20.*t
 
y=y+30
 
y =
 
-4.8768*t^2+20.*t+30
 
y0=subs(y,t,30)
 
y0 =
 
  -3.7591e+03
 
y0=subs(y,t,0)
 
y0 =
 
    30
 
t_top=solve(v)
 
t_top =
 
2.0505
 
subs(y,t,t_top)
 
ans =
 
50.505
 
t_splat=solve(y)
 
t_splat =
 
[ -1.1676]
[  5.2686]
 
t_bunk=solve(y-1.7)
 
t_bunk =
 
[ -1.1130]
[  5.2140]
 
----------------------------------------------------
>> syms t
>> v=int(a,t)
 
v =
 
-9.7536000000000000000000000000000*t
 
>> t=sym('t')
 
t =
 
t
 
>> a=sym('-9.7536')
 
a =
 
-9.7536
 
>> v=int(a,t)
 
v =
 
-9.7536000000000000000000000000000*t
 >> v=v+20
 
v =
 
-9.7536000000000000000000000000000*t+20
 
>> h=int(v,t)
 
h =
 
-4.8768000000000000000000000000000*t^2+20.*t
 
>> ezplot(h,[0,6])
 
%%%% Taylor series(help taylor) %%%%%%
 
>> x=sym('x');
>> f=taylor(log(x+1)/(x-5))
 
f =
 
-1/5*x+3/50*x^2-41/750*x^3+293/7500*x^4-1207/37500*x^5
 
>> pretty(f)
 
                                2   41   3   293   4   1207   5
                - 1/5 x + 3/50 x  - --- x  + ---- x  - ----- x
                                    750      7500      37500
>> 
>> clear f
>> f=(x^2 - 1)*(x-2)*(x-3)
 
f =
 
(x^2-1)*(x-2)*(x-3)
 
>> collect(f)
 
ans =
 
x^4-5*x^3+5*x^2+5*x-6
 
>> horner(ans)
 
ans =
 
-6+(5+(5+(x-5)*x)*x)*x 
 
>> factor(f)
 
ans =
 
(x-1)*(x+1)*(x-2)*(x-3)
 
>> expand(f)
 
ans =
 
x^4-5*x^3+5*x^2+5*x-6
 
>> clear all
>> syms x y z a
>> simplify(log(2*x/y))
 
ans =
 
log(2)+log(x/y)
 
>> simplify((-a^2+1)/(1-a))
 
ans =
 
a+1
 
>> clear 
>> 
>> x=sym('x');
>> f=(1/x^3+6/x^2+12/x+8)^(1/3)
 
f =
 
(1/x^3+6/x^2+12/x+8)^(1/3)
 
>> g=simple(f)
 
g =
 
(2*x+1)/x
 
>> h=simple(g)
 
h =
 
2+1/x
 
>> clear 
>> s=sym('s')
 
s =
 
s
 
>> Y=(10*s^2+40*s+30)/(s^2+6*s+8)
 
Y =
 
(10*s^2+40*s+30)/(s^2+6*s+8)
 
>> diff(int(Y))
 
ans =
 
10-15/(s+4)-5/(s+2)
 
>> pretty(ans)
 
                                    15       5
                              10 - ----- - -----
                                   s + 4   s + 2
>> x=sym('x')
 
x =
 
x
 
>> g=(x^3+5)/(x^2-1)
 
g =
 
(x^3+5)/(x^2-1)
 
>> diff(int(g))
 
ans =
 
x+3/(x-1)-2/(x+1)
 
>> pretty(ans)
 
                                     3       2
                               x + ----- - -----
                                   x - 1   x + 1
>> 
 
>> format long
>> pi
 
ans =
 
   3.14159265358979
 
>> digits
 
Digits = 32
 
>> vpa(pi)
 
ans =
 
3.1415926535897932384626433832795
 
>> vpa(pi,5)
 
ans =
 
3.1416
 
>> A=[sym('1/4'),sym('sqrt(2)');sym('exp(1)'),sym('3/7')]
 
A =
 
[     1/4, sqrt(2)]
[  exp(1),     3/7]
 
>> vpa(A,5)
 
ans =
 
[ .25000, 1.4142]
[ 2.7183, .42857]
 
>> vpa(pi*sqrt(163),20)
 
ans =
 
 >> syms a b c x
>> solve(a*x^2 + b*x +c)
 
ans =
 
[ 1/2/a*(-b+(b^2-4*a*c)^(1/2))]
[ 1/2/a*(-b-(b^2-4*a*c)^(1/2))]
 
>> pretty(ans)
 
                          [           2         1/2]
                          [    -b + (b  - 4 a c)   ]
                          [1/2 --------------------]
                          [             a          ]
                          [                        ]
                          [           2         1/2]
                          [    -b - (b  - 4 a c)   ]
                          [1/2 --------------------]
                          [             a          ]
>> solve('a*x^2 + b*x = -c')
 
ans =
 
[ 1/2/a*(-b+(b^2-4*a*c)^(1/2))]
[ 1/2/a*(-b-(b^2-4*a*c)^(1/2))]
 
>> solve(a*x^2 + b*x +c,b)
 
ans =
 
-(a*x^2+c)/x
 
>> pretty(ans)
 
                                       2
                                    a x  + c
                                  - --------
                                       x
>> 
 
 
>> solve(x+1)
 
ans =
 
-1
 
>> solve(cos(x)-sin(x))
 
ans =
 
1/4*pi
 
>> double(ans)
 
ans =
 
   0.78539816339745
 
>> clear all
>> syms x y z
>> [a1 a2]=solve(x^2+x*y_y-3,x^2-4*x+3)
??? Undefined function or variable 'y_y'.
 
>> [a1 a2]=solve(x^2+x*y+y-3,x^2-4*x+3)
 
a1 =
 
[ 1]
[ 3]
 
 
a2 =
 
[    1]
[ -3/2]
 
>> S=solve(x^2+x*y_y-3,x^2-4*x+3)
??? Undefined function or variable 'y_y'.
 
>> S=solve(x^2+x*y+y-3,x^2-4*x+3)
 
S = 
 
    x: [2x1 sym]
    y: [2x1 sym]
 
>> S.y
 
ans =
 
[    1]
[ -3/2]
 
>> S.x
 
ans =
 
[ 1]
[ 3]
 
>> S=solve(sin(x+y)-exp(x)*y,x^2-y-2)
 
S = 
 
    x: [1x1 sym]
    y: [1x1 sym]
 
>> S.x
 
ans =
 
-6.0173272500593065641097297117905
 
>> S.y
 
ans =
 
34.208227234306296508646214438330
 
>> clear a
>> clear
>> syms d n p q
>> eq1=d+n/2+p/2-q;
>> eq2=n+d+q-p-10;
>> eq3=q+d-n/d-p;
>> eq4=q+p-n-8*d-1;
>> S=solve(eq1,eq2,eq3,eq4)
 
S = 
 
    d: [2x1 sym]
    n: [2x1 sym]
    p: [2x1 sym]
    q: [2x1 sym]
 
>> S.d
 
ans =
 
[ 4+i*15^(1/2)]
[ 4-i*15^(1/2)]
 
>> S.n
 
ans =
 
[ 35/4+1/4*i*15^(1/2)]
[ 35/4-1/4*i*15^(1/2)]
 
--------------------------------------------
 
>> syms y
>> Dy=1+y^2
 
Dy =
 
1+y^2
 
>> dsolve('Dy=1+y^2')
 
ans =
 
tan(t+C1)
 
>> dsolve('Dy=1+y^2,y(0)=1')
 
ans =
 
tan(t+1/4*pi)
 
 
>> dsolve('D2y-2*Dy-3*y=0','y(0)=0','y(1)=1')
 
ans =
 
1/(exp(3)-exp(-1))*exp(3*t)-1/(exp(3)-exp(-1))*exp(-t)
 
>> y=simple(ans)
 
y =
 
(exp(3*t)-exp(-t))/(exp(3)-exp(-1))
 
>> pretty(y)
 
                              exp(3 t) - exp(-t)
                              ------------------
                               exp(3) - exp(-1)
>>ezplot(y,[-6,2])
 
 
>> [t g]=dsolve('Df=3*f+4*g','Dg=-4f+3*g')
 
t =
 
-16/9+exp(3*t)*(C1+4*t*C2)
 
 
g =
 
exp(3*t)*C2+4/3
 
>> [t g]=dsolve('Df=3*f+4*g','Dg=-4f+3*g','f(0)=0','g(0)=1')
 
t =
 
-16/9+exp(3*t)*(16/9-4/3*t)
 
 
g =
 
-1/3*exp(3*t)+4/3
 
 
---------------------------------------------------
 
Maple using matlab
 
>> maple('f:=x+2*t*y-t-2*t^3;')
 
ans =
 
f := x+2*t*y-t-2*t^3
 
 
%g=dt/dt
>> maple('g:=diff(f,t)')
 
ans =
 
g := 2*y-1-6*t^2
 
>> maple('g:=diff(f,y)')
 
ans =
 
g := 2*t
 
>> maple('g:=diff(f,x)')
 
ans =
 
g := 1
 
 
>> maple('g:=diff(f,t)')
 
ans =
 
g := 2*y-1-6*t^2
 
>> maple('h:=solve(g,y)')
 
ans =
 
h := 1/2+3*t^2
 
 
>> clear
>> syms x t y
>> f = x+2*t*y-t-2*t^3
 
f =
 
x+2*t*y-t-2*t^3
 
 
%Solve g=0 for y
>> g=diff(f,t),h=solve(g,y)
 
g =
 
2*y-1-6*t^2
 
 
h =
 
1/2+3*t^2
 
 
 
%\dx/dt = x/t - x
>> maple('a:=diff(x(t),t)=x(t)/t-x(t)')
 
ans =
 
a := diff(x(t),t) = x(t)/t-x(t)
 
>> maple('b:=dsolve(a,x(t))')
 
ans =
 
b := x(t) = _C1*t*exp(-t)
 
 
 
%\int_{y_0}^{y_1} 1/\sqrt(c-y)
>> maple('c:=2;a:=int(1/sqrt(c-y),y=y_0..y_1)')
 
ans =
 
c := 2a := -2*(2-y_1)^(1/2)+2*(2-y_0)^(1/2)
 
 
 
>> maple('A:=matrix([[1, 1, 0, 3],[2, 1, -1, 1],[3, -1, -1, 2],[-1 ,2, 3, -1]])')
 
ans =
 
A := matrix([[1, 1, 0, 3], [2, 1, -1, 1], [3, -1, -1, 2], [-1, 2, 3, -1]])
 
>> maple('x:=''x'' ')
 
ans =
 
x := 'x'
 
>> maple('b:=array(1..4,[4,1,-3,4])')
 
ans =
 
b := vector([4, 1, -3, 4])
 
>> maple('x:=linsolve(A,b)')
 
ans =
 
x := vector([-1, 2, 0, 1])