Mat3012 Numerical Analysis (Lab Applicatoins) : Bahcesehir University
Mat3012 Numerical Analysis (Lab Applicatoins) : Bahcesehir University
Week-1, Spring
https://akademik.bahcesehir.edu.tr/web/aysunsoysal/tr/index.html
Email: [email protected]
Software: MATLAB
1. MATLAB Environment
2. Some Useful Commands
3. Input-Output Function
4. Array, Vector and Matrix
5. Mathematical Functions and Operations
3
1. MATLAB ENVIRONMENT
MATLAB is a computer program that provides the user with a convenient environment for
performing many types of calculations. In particular, it provides a very nice tool to implement
numerical methods.
4
2. SOME USEFUL COMMANDS IN MATLAB
• help gives information about specific MATLAB command or function; e.g. ‘help for’.
• doc displays documentation for the MATLAB function in the Help browser; e.g. ‘doc for’.
• pwd exracts the address of your current working directory.
>> pi
ans =
3.1416
>> format long
>> pi
ans =
3.141592653589793
Two functions provide ways to enter and display information directly using the command
window:
• The input function
• The disp function
7
▪ The input function. This function allows you to prompt the user for values directly from the
command window. Its syntax:
n=input(‘prompt string’)
i.e., this function displays the prompt string, waits for keyboard input, and then returns the value
from the keyboard.
• If the user enters a value, it would then • If the user enters a string, an ‘s’ is
be assigned to the variable m. appended to the function’s argument list.
>> m=input('Enter your age:') >> name=input('Enter your name:','s')
Enter your age: 31 Enter your name: Aysun
m= name =
31 Aysun 8
▪ The disp function. This function provides a handy way to display a value. Its syntax:
disp(value)
where value= the value you would like to display. It can be a numeric costant or variable, or a
string enclosed hyphens.
9
4. ARRAY, VECTOR AND MATRIX
>> B=[1 3 6 ;3 9 7 ; 2 1 0]
>> size(B)
ans = 12
3 3
5. MATHEMATICAL FUNCTIONS AND OPERATIONS
! help elfun helps to take a look at the built-in functions which are commonly in use.
^ exponentiation
~ negation
* multiplication
/ division
\ left division (applies to matrix algebra)
+ addition
- substraction
13
Ex1. Evaluate 𝑒 −𝑎 𝑠𝑖𝑛𝑥 + 10 𝑦 on MATLAB when 𝑎 = 5, 𝑥 = 2, 𝑎𝑛𝑑 𝑦 = 8.
>> a=5;x=2;y=8;
>> exp(-a)*sin(x)+10*sqrt(y)
ans =
28.2904
Ex2.
>> t=0:pi/5:2*pi
t=
0 0.6283 1.2566 1.8850 2.5133 3.1416 3.7699 4.3982 5.0265 5.6549
6.2832
14
Ex3.
>> A
A=
2 4 6 8
10 12 14 16
>> sin(A)
ans =
0.9093 -0.7568 -0.2794 0.9894
-0.5440 -0.5366 0.9906 -0.2879
Ex4.
>> t=1:5
t=
1 2 3 4 5
>> s=t.^2
s= 15
1 4 9 16 25
THANK YOU FOR YOUR ATTENTION !
16