0% found this document useful (0 votes)
7 views

Matlab Math-2 2024 2

Matlab Cheat sheet help

Uploaded by

dizajnocelka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Matlab Math-2 2024 2

Matlab Cheat sheet help

Uploaded by

dizajnocelka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Math2, Dorthe Wildt Nielsen, SDU, 11th of April, 2024

MATLAB-commands Math2, 2024

Integration Techniques

Indefinite Integration
Example: x) 3 x 2 + x
f (= syms x f(x) =
f(x)=3*x^2+x
ans =
int(f(x),x)
∫ f (=
x) dx ∫ (3 x 2
+ x) dx

(Note: The arbitrary constant c is not added


by MATLAB)

Definite Integration
Example: f (=
x) 3 x 2 + x , [ a, b] = [ −2, 4]
4 4
syms x
∫ f (=
x) dx ∫ (3 x 2
+ x) dx f(x)=
−2 −2
f(x)=3*x^2+x
int(f(x),x,-2,4) ans =

Integral with infinite limit(s)


syms x
f ( x) = e −5 x f(x)=exp(-5*x)
f(x) =
∞ ∞
int(f(x),x,0,inf)

0
f ( x) dx = ∫ e −5 x dx
0
ans =
Math2, Dorthe Wildt Nielsen, SDU, 11th of April, 2024

Laplace Transform

Laplace Transform

Example: f (t ) = e −5t syms t s f(t)=


f(t)=exp(-5*t)
L { f (t )} = F ( s ) F(s)=laplace(f(t)) F(s) =

Inverse Laplace Transform


2s + 6
F (s) = syms t s
F(s) =
s2 + 4 F(s)=(2*s+6)/(s^2+4)
f(t)=ilaplace(F(s))
f (t ) = L−1{ F ( s} f(t) =

Partial Fractions partial_fractions =


syms s
2
F (s) = F(s)=2/((s+1)*(s+2)*(s+3))
( s + 1)( s + 2)( s + 3) partial_fractions=partfrac(F(s))
A B C
= + +
s +1 s + 2 s + 3
Math2, Dorthe Wildt Nielsen, SDU, 11th of April, 2024

Fourier Series Fourier series expansion of f (t ) (n=3 on graph):


2
Example: f (t )= π − ∑ sin(nt )
n =1 n

Periodic function f (t ) of period 2 π defined


by:
f (t )= t (0 < t < 2π ) f (t )= f (t + 2π )

MATLAB-code:
syms x y t
t=linspace(0,2*pi); % A lot of values of f(t) are calculated between t=0 and t=2pi
x=t;
s=3; %Size of series, change accordingly
FourierSeries=0; % Sets the variable to 0 before start
for n=1:s % When s=3 the sum consists of the 3 terms
FourierSeries=FourierSeries+2/n*sin(n*t); % In the example the harmonics are -2/n*sin(nt)
% "-" is incorporated in the
% next line
end
y=pi-FourierSeries; % pi is equal to the dc term in the example,
% values from "FourierSeries" are subtracted according
% to the expression of the Fourier expansion
plot(x,y)
title("n=3") % Value of n (should be changed when s is changed)
xline(0) % coordinate axis
yline(0) % coordinate axis
Math2, Dorthe Wildt Nielsen, SDU, 11th of April, 2024

Data Handling: Statistical descriptors and histogram

MATLAB code:

Typing data into data=[x1, x2, …, xn] Choose an appropriate name, commas not
MATLAB: necessary
Example:
data=[7,3,8,6,10,6,2,9,5,8,2,7,1,7]

Histogram hist(data,[1:1:10])

% hist(name of data, [start, stepsize, end]

Average (mean) mean(data) ans = 5.7857

Standard deviation std(data) ans = 2.8060

Median median(data) ans = 6.5000

Sorting data sort(data) ans = 1×14


1 2 2 3 5 6
6 7 7 7 8 8 9
10
Range range(data) ans = 9
Math2, Dorthe Wildt Nielsen, SDU, 11th of April, 2024

Probability Theory
MATLAB code:

Binomial coefficients nchoosek(n,k)


n Example: nchoosek(20,2) % n=20 k=2 ans = 190
 
k 

Binomial distribution Binomial probability density function:


binopdf(k,n,p)
X  B(n, p )
Example: p=binopdf(0,20,0.05) % P(X=0), n=20, p=0.05 p = 0.3585
n
P( X= k=
)   p k (1 − p ) n − k Binomial cumultative distribution function
k  p=binocdf(k,n,p)

P( X ≤ k ) Example: p=binocdf(3,16,0.05) % P(X<=3), n=16, p=0.05


p = 0.9930

Poisson distribution Poisson probability density function:


poisspdf(x, λ )
X  Po(λ )
Example: p=poisspdf(2,0.8) % P(X=2), λ =0.8
p = 0.1438
λ e
k −λ
Poisson cumultative distribution function:
P( X= k=
) poisscdf(x,lambda)
k!
P( X ≤ k ) Example: p=poisscdf(3,4) % P(x<=3),lambda = 4 p = 0.4335

Normal distribution Normal cumulative distribution function


X  N (µ X ,σ X ) p=normcdf( x , µ X , σ X )

Example: p=normcdf(550,600,25) % P ( X < 550) = P ( X ≤ 550) p = 0.0228

You might also like