Introduction To MATLAB: Done By: Eng. Shima' Abed Rabbo Eng. Arwa Aqel
Introduction To MATLAB: Done By: Eng. Shima' Abed Rabbo Eng. Arwa Aqel
Introduction To MATLAB: Done By: Eng. Shima' Abed Rabbo Eng. Arwa Aqel
Name Meaning
Inf Infinity.
Command Purpose
Operator Purpose
\ Left-division operator.
/ Right-division operator.
Command Purpose
== Equal to.
~= Not Equal to .
Apart from the above-mentioned relational operators,
MATLAB provides the following commands/functions
used for the same purpose :
Function Description
ind = find(X) Find indices and values of nonzero elements; locates all
nonzero elements of array X, and returns the linear
indices of those elements in a vector. If X is a row
vector, then the returned vector is a row vector;
otherwise, it returns a column vector. If X contains no
nonzero elements or is an empty array, then an empty
array is returned.
Programming Commands
1. If / if else
2. Switch
3. While
4. For
5. Break
6. Continue
Decision Making (if / if else):
>> x = 2, y = 3;
>> switch x
>> case x==y
>> disp('x and y are equal');
>> case x>y
>> disp('x is greater than y');
>> otherwise
>> disp('x is less than y');
>> end
x is less than y
LOOP TYPES :
Example:
Functions can accept more than one input arguments and may
return more than one output arguments Syntax of a function
statement is :
Plotting Commands :
To plot the graph of a function, you need to take the
following steps:
Generating Sub-Plots :
Example 1 : (array)
fx>> x = [ -2 -1 0 1 2 3 4 5 6 ];
y = [ -2 -1 0 1 2 3 4 5 6];
plot(x,y,'g-')
Example 2 : (interval)
fx>> syms x y
x= 0:0.5:4
y=exp(x)
plot(x,y)
Example 3:
fx>> x = 0:0.1:2;
y=sin(x);
z=cos(x);
plot (x,y,'b--*',x,z,'ro')
xlabel('x')
ylabel('sin and cos')
title ('function')
legend('sin(x)','cos(x)')
grid on
ALGEBRA :
Solving Basic Algebraic Equations in MATLAB .
Solving Quadratic Equations in MATLAB .
Solving Higher Order Equations in MATLAB .
Example 1:
Solve the following equations on matlab (i.e. find the value of x, y and z ?)?
3x + 10y - z = 0
-2x + y - 10z = -2
x+y-z=3
x
y
z
Example 2:
Solve the following polynomial function f(x) on matlab (i.e. find the value of x?)?
f(x) = x4 + 7x3 - 5x + 9
** There are different ways to find the root x:
Example 3:
Find the value of the following polynomial function f(x) at x = 0 on matlab (i.e. find f(x=0) ?
f(x) = x2 - 7x + 12
** There are different ways to find f(0):
DIFFERENTIAL
Let us find the stationary points of the function f(x) = 2x3 + 3x2 − 12x + 17.
Take the following steps :
Ex : (step #1)
syms x
y = 2*x^3 + 3*x^2 - 12*x + 17; % defining the function
ezplot(y)
(step #2):
syms x
y = 2*x^3 + 3*x^2 - 12*x + 17; % defining the function
ezplot(y, [-2, 2])
(step#3):Next, let us compute the derivative.
g = diff(y)
(step #4):Let us solve the derivative function, g, to get the values where it becomes
zero.
s = solve(g)
INTEGRATION