0% found this document useful (0 votes)
80 views27 pages

Introduction On Matlab: Engineering Analysis Instructor: Dr. Jagath Nikapitiya

The document is an introduction to using MATLAB for engineering analysis. It covers various numerical calculation, plotting, and analytical calculation functions in MATLAB including the gamma function, Bessel functions, solving equations, loops, differentiation, integration, solving equations, simplifying and expanding functions, and plotting multiple functions on the same axes or in 3D. Examples of using each function are provided.

Uploaded by

Suprio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views27 pages

Introduction On Matlab: Engineering Analysis Instructor: Dr. Jagath Nikapitiya

The document is an introduction to using MATLAB for engineering analysis. It covers various numerical calculation, plotting, and analytical calculation functions in MATLAB including the gamma function, Bessel functions, solving equations, loops, differentiation, integration, solving equations, simplifying and expanding functions, and plotting multiple functions on the same axes or in 3D. Examples of using each function are provided.

Uploaded by

Suprio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Introduction on Matlab

A L I G H A MA RTA L A

Engineering Analysis
Instructor: Dr. Jagath Nikapitiya

Faculty of Engineering and Applied Science


Memorial University of Newfoundland
February 2019
Introduction

2
Numerical Calculation

3
Numerical Calculation

4
Numerical Calculation

5
Numerical Calculation

6
Numerical Calculation

7
Numerical Calculation

8
Numerical Calculation

9
Numerical Calculation

10
Gamma function
• 1. fplot ⇒ fplot(@gamma)
• 2. script ⇒ x=-5:0.1:5; y=gamma(x); plot(x,y)

11
Solve equation that has gamma function

gamma(1/3)/3
Solution:
ans =
3*sqrt(pi)*gamma(2/3)/gamma(1/6)
0.892979511569249
ans =

1.2936
format long
ans =

1.293554779614895

12
Format of Numbers

13
Bessel functions
• Bessel function J ( Z ) (besselj(nu,Z))
x=0:0.1:9;
y0=besselj(0,x);
y1=besselj(1,x);
y2=besselj(2,x);
y(length(x))=0;
plot(x,y,'-.')
hold on
plot(x,y0)
hold on
plot(x,y1)
hold on
plot(x,y2)
legend('y=0','J_0','J_1','J_2')

14
Bessel functions
• Bessel function Y ( Z ) (bessely(nu, Z))
x=0:0.1:20;
y(length(x))=0;
y0=bessely(0,x);
y1=bessely(1,x);
y2=bessely(2,x);
plot(x,y,'-.’);
hold on;
plot(x,y0);
hold on;
plot(x,y1);
hold on;
plot(x,y2);
legend('y=0','Y_0','Y_1','Y_2')
axis([-0.1 20.2 -2 0.6])

15
Example

Solution:
x=0:0.1:10;y1=x.*besselj(2/3, x.^(3/2)); y2=x.*besselj(-2/3,x.^(3/2));
ploy(x,y1);
hold on
plot(x,y2);

16
Bessel function root
• fsolve:
eqn = @(x) besselj(nu, x) ;
x0 = [first guess] ;
x = fsolve(eqn,x0)
-------------------------------------------------------
eqn = @(x) besselj(0, x) ;
x0 = [2, 5, 8, 11, 14] ; OR x0=0:20
x = fsolve(eqn,x0)
Result:
x=

2.4048 5.5201 8.6537 11.7915 14.9309

17
Bessel function root
eqn = @(x) besselj(1, x) ; eqn = @(x) bessely(1, x) ;
x0 = [3, 7, 10, 13, 16] x0 = [2, 5, 8, 11, 14]
x = fsolve(eqn,x0)
x = fsolve(eqn,x0) Result:
Result: x=
x= 2.1971 5.4297 8.5960 11.7492 14.8974

3.8317 7.0156 10.1735 13.3237 16.4706


eqn = @(x) bessely(0, x) ;
x0 = [1, 3, 7, 10, 13]
x = fsolve(eqn,x0)
Result:
x=
0.8936 3.9577 7.0861 10.2223 13.3611

18
Example

eq=@(x) besselj(-1/3,x);
x0=1:10;
x=fsolve(eq,x0)

Solution:

x=

Columns 1 through 5

1.866350858873868 1.866350858873891 1.866350836187152 4.987853231435111 4.987853231435159

Columns 6 through 10

4.987853231435157 8.124265381939693 8.124265381939693 8.124265381939693 11.263514825427654

19
Loops
• while, for, if, switch and case:

while x<2 or x~=2


… switch a
end case 1

for i=1:10
case -1
… …
end end
If a==2 or a>2 && b<3 or a>2 || b<3

elseif a>2

else
….
end

20
Analytical Calculation

21
Analytical Calculation

22
Analytical Calculation
Function Example
𝑑𝑓
diff(function, variable) 𝑑𝑥
⇒ diff(f, x)
+𝑏
int(function, variable, lower bound, upper bound) ‫׬‬−𝑏 𝑓 𝑑𝑥 ⇒ int(f, x, -b, +b)
f = a*x^2+b*x+c ⇒
solve(f, x)⇒
solve(function, variable) x1 = -(b + (b^2 - 4*a*c)^(1/2))/(2*a)
x2 = -(b - (b^2 - 4*a*c)^(1/2))/(2*a)
subs(function, variable) subs(f, x, 2) ⇒ 4*a + 2*b + c
• expand((x+1)^3) ⇒ x^3+3*x^2+3*x+1
expand(function) • expand(sin(x+y)) ⇒ sin(x)*cos(y)+cos(x)*sin(y)
• expand(exp(x+y)) => exp(x)*exp(y)
• simplify(sin(x)^2 + cos(x)^2) ⇒ 1.
• simplify(exp(c*log(sqrt(alpha+beta)))) ⇒ (alpha +
simplify(function) beta)^(c/2).
• simplify(sqrt(x^2)) ⇒ sqrt(x^2),

23
Plot

>>x=0:pi/100:2*pi;
>>y1=sin(x);
>>y2=sin(x-0.25);
>>y3=sin(x-0.5);
>>plot(x,y1,x,y2,x,y3)
>>legend(‘sin(x)’,’sin(x-0.25)’,’sin(x-0.5)’)

xlabel (‘’)
ylabel (‘’)
title(‘’)

24
Plot

>>syms x y
>>ezplot(sin(x^2)-cos(y))

25
Analytical Calculation

26
Plot

>>x=-2:0.2:2;
>>y=-2:0.2:2;
>>[x,y]=meshgrid(x,y);
>>z=x.*exp(-x.^2-y.^2);
>>mesh(z)
Or
>>surf(x,y,z)

27

You might also like