Professional Documents
Culture Documents
Omeralusi مادة امتحان شهر أول حاسوب
Omeralusi مادة امتحان شهر أول حاسوب
Lecturer:
Mr. Munther R.
Content
Chapter 1: The Desktop Window and Basic Mathematical Definitions
Introduction
MATLAB Windows
Basic Arithmetic
General Command
Basic Mathematical Definitions
Complex Numbers
Introduction
MATLAB Windows
The Basic Arithmetic
General Command
Basic Mathematical Definitions
Complex Numbers
ٚرؼزجص ٌ خ ٌ MATLABخ ثصِغخ ػبٌ١خ األذاء رػزدرَ إلعصاء اٌؾػبثبد اٌص٠بظا١خ ٚإٌٙرغا١خ ٚاٌزمٕ١ابد اٌؼٍاَٛ
االخص ٜذ ٚرم َٛثؼٍّ١بٌد اٌؾػبثبد ٚاظٙبش إٌزبئظ ظّٓ ث١ئخ غٍٙخ اٌجصِغخ ذ ٚرّىٕاذ ٘اس اٖ اٌٍ اخ ِآ ؽاً اٌؼر٠ار ِآ
اٌّػبئً اٌّؼمرح ِمبشٔزب ِغ ثصِغخ ثٍ بد اٌجصِغخ األخصِ ٜضً ٌ خ . FORTAN ٚ C
أرذ رػّ١خ ٘سٖ اٌٍ خ ِٓ اخزصبش اٌزؼج١ص ِ) MATrix LABoratoryدزجص اٌّصفٛفخ( ز ْ اٌجصٔبِظ ِصاُّ
أغبغب ٌٍزؼبًِ ِغ اٌؼٍّ١بد ػٍ ٝاٌّصفٛفبد ثشىً اوضاص ثػابغخ ٚأػاغبَ .كما أرفقا بهاهِ اللغا أدوا ٌّؼبٌغاخ ٚؽاً
اٌزطج١مبد ػٍّ١خ خبصخ ِ ٖٛ٘ٚب٠ؼصف ثصإرٚق االذٚاد )ٚ (Toolboxesرؼزجاص ٘اسٖ األذٚاد ٘بِاخ عارا ٌّػازدرَ ٘اسٖ
اٌٍ خ ذ ثبالظبفخ اٌ ٝاْ ثصٔبِظ ٠ MATLABارػُ ثضماخ أدوا التخ طا ِب لرواوم )(Graphical User Interface
GUIاٌز ٟرغؼً اٌّػزدرَ ٠زؼبًِ ِغ اٌٍ خ اٌجصٔبِظ ٚوبُٔٗ اذاح ػٍّ١خ ِزطٛشح غج ٗٙ١ثج١ئٗ ٌ بد ف١غٛي .
وبعد فتح البرنامج ,عندها ستظهر لنا شاشة تحمل أسم البرنامج MATLABونسخة اإلصار و دار وسنة النشرر
كما في الشكل ( , )1ثم بعد ثوان قليلة ستظهر نافذة البرنامج الرئيسية والتي تكرون فري بدايرة تشر بل البرنرامج مول مررة
وّب ف ٟاٌشىً (. )2
الشكل 1
شكل 3
Symbol المعنى
ans إٌز١غخ إٌٙبر١خ الخص ػٍّ١خ ؽػبث١خ اٌّ ٚز ١ص غ١ص ِؼصف ِػجمب
pi إٌػجخ اٌضبثزخ π
i, j اٌغسش اٌزد 1 ٍٟ١
inf اٌمػّخ ػٍ ٝصفص
NaN ػٍّ١خ خبغئخ ٚغ١ص ِمجٌٛخ ِضً 0/0
theta اٌصِط θ
phi اٌصِط ϕ
eita اٌصِط η
جدول 2
Symbol الوظيفة
% ٚظغ ِلؽظبد رٛظ١ؾ١خ
clc ٌزٕظ١ف ٔبفسح ِٓ Command Windowاٌىزبثخ
clear ِػؼ اٌج١بٔبد اٌّرخٍخ ٚإٌبرغخ Workspace
; ػرَ أظٙبش إٌزبئظ ػٍٔ ٝبفسح Command Window
format long اظٙبش االشلبَ ثص ١خ ِصارت ػشص٠خ اوضص
format short اظٙبش االشلبَ ثص ١خ ِصارت ػشص٠خ الً
format rat اظٙبش االشلبَ ثص ١خ وػص٠خ
ceil اػطبء اوجص ػرذ صؾ١ؼ ٚاٌزمص٠ت اٌ-∞ ٝ
floor اٌزمص٠ت اٌ+∞ ٝ
fix اٌزمص٠ت اٌzero ٝ
help ٠ؼصف اٌراٌخ ٚٚظ١فزٙب ٚو١ف١خ اغزدراِٙب
mod ٠دصط ٔبرظ اٌمػّخ ٌٍؼرذ اٌصؾ١ؼ
rem ٠دصط ثبل ٟاٌمػّخ
جدول 3
ِلؽظخ :عّ١غ اٚاِص MATLABرىزت ثبٌؾصٚف االٔىٍ١ط٠خ اٌص ١صح Small Letters
)>> A = sqrt(11
= A
3.3166
Symbol المعنى
a+bi ص ١خ اٌؼرذ اٌّصوت
real اٌغسش اٌؾم١مa ٟ
conj اٌغسش اٌزدb ٍٟ١
abs ٔصف لطص اٌؼرذ اٌّصوت a 2 b 2
b
angle ضا٠ٚخ اٌؼرذ اٌّصوت tan 1
a
جدول 4
C
Vectors and Matrices
: ٍٟ٠ وّبٚ ثبٌؼىعٚ ِزغٗ صفٌٝذ اّٛ (') رػزدرَ ٌؼىع ِزغٗ اٌؼ
>> x=a'
x =
2 1 4
>> y=b'
y =
3
5
2
>> e=4+c
= e
7
11
13
>> f=3*c
= f
9
21
27
1 4
2 5
3 6
]>> y=[100:-5:80
= y
100 95 90 85 80
ٟ اٌعصة إٌمط.1
A (a1 a 2 a3 ....a n )
B (b1 b2 b3 ....bn )
n
A B ai * bi
i 1
>> d=cross(a,b)
d =
27
9
-9
>> x=a';y=b';
>> z=dot(x,y)
z =
33
>> w=cross(x,y)
w =
27 9 -9
>> a=[12;17;-2;0;4;5;11;15;27];
>> a(2) استدعاء عىصز
ans =
17
1 7
12 18
= p
-2.0000 0.1667
0.7143 0.6364
= g
>> eye(3,4)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
>> eye(4,3)
ans =
1 0 0
0 1 0
0 0 1
0 0 0
(zeros) خ٠فخ اٌصفصٛ ِصف
>> zeros(4)
ans =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> zeros(3,4)
ans =
0 0 0 0
0 0 0 0
0 0 0 0
(ones) خ٠فخ االؽبذٛ ِصف
>> ones(3)
ans =
1 1 1
1 1 1
1 1 1
Lecturer: Mr. Munther R.
18
)>> ones(3,4
= ans
Finding Determinants and Solving LinearSystems ٌايجاد محدد وحل معادالت الخطج
disp عٍّخ-2
>> d=8;
>> disp(d)
8
>> sum=9.8;
>> disp(['sum=',num2str(sum)])
sum=9.8
error عٍّخ-3
error('errmsg')
fprintf عٍّخ-4
fprintf('text %formatcode \controlcode',var1,.....)
>> x=104.76;
>> fprintf('the value of x is = %5.3f \n',x)
the value of x is = 104.760
>> a=2;
>> d='ali';
>> fprintf('the number %d is = %s \n',a,d)
the number 2 is = ali
>> i=1;
>> while i<7
disp(i)
i=i+1;
end
1
2
3
4
5
6
>> i=1;
>> while i>0
disp(i)
i=i+1;
end
1
2
3
4
5
6
.
.
Ctrl+C
if expression
commands
end
if expression
commands evaluated if True
else
commands evaluated if False
end
if expression 1
commands 1 evaluated if True
elseif expression 2
commands 2 evaluated if True
elseif expression 3
commands 3 evaluated if True
.
.
.
.
elseif expression n
commands n evaluated if True
else
commands other are False
end
>> x=5;
>> if x>4
disp('OK')
else
disp('NO')
end
OK
>> x=7;
>> y=7;
>> if x>y
fprintf('x>y where x is %d and y is %d\n',x,y)
elseif x<y
fprintf('x<y where x is %d and y is %d\n',x,y)
elseif x==y&x>1
fprintf('x and y are positive numbers x=y= %d\n',x)
else
fprintf('x and y are negative numbers x=y= %d\n',x)
end
x and y are positive numbers x=y= 7
switch index
case {expression 1}
commands 1 evaluated if True
case {expression 2}
commands 2 evaluated if True
case {expression 3}
commands 3 evaluated if True
.
.
.
case {expression n}
commands n evaluated if True
otherwise
commands other are False
end
m =
8.6603
M-File M الملف
ٍٝي ػٛؽصٚ بٙم١اِص ِصاذ رطجٚؼ ثىزبثخ اال١ز٠ ٞاٌسٚ MATLAB ثصٔبِظٟذح فٛعِٛ اع اٌٍّفبدٛٔع ِٓ اٛٔ ٛ٘
ُِآ صاٚ (.m) ب رؾفع ثشىً ٍِف ثبِزراذٙبء ِٓ وزبثزٙػٕر االٔزٚ س١ْ رٕفٚاِص رىزت ثشىً وبًِ ثرٚب ذ از اْ رٍه االٙٔزبئغ
.(Command Window) اِصٚ ٔبفسح االٍٝص ٔزبئغٌٗ ػٙسُٖ ٌزظ١رٕف
x=7;
y=7;
if x>y
fprintf('x>y where x is %d and y is %d\n',x,y)
elseif x<y
fprintf('x<y where x is %d and y is %d\n',x,y)
elseif x==y&x>1
fprintf('x and y are positive numbers x=y= %d\n',x)
else
fprintf('x and y are negative numbers x=y= %d\n',x)
end
: ٌٟوبٌزبٚ اِصٚ ٔبفسح االٍٝغخ ػ١ص إٌزٙثؼر زٌه غزظٚ س١ ضش اٌزٕفٍَٝ ثبٌع ػ ػٛثؼر اٌؾفع اٌٍّف ٔم
function z=sumxy(x,y)
% x is first number
% y is second number
% z is answer
z=x+y;
end
: y ٚ x ُ١اِص صُ ٔرخً لٚ ٔبفسح االٍٝ( ػsumxy) َ ثىزبثخ اغُ اٌراٌخٛثؼر اٌؾفع اٌٍّف ٔم
>> sumxy(4,5)
ans =
9
function [outvar1,outvar2,outvar3,…]=funcname(inpvar1,inpvar2,…. )
% helpcomments
commands
outvar=value
end
: y ٚ x ُ١اِص صُ ٔرخً لٚ ٔبفسح االٍٝ( ػmiltxy) َ ثىزبثخ اغُ اٌراٌخٛثؼر اٌؾفع اٌٍّف ٔم
>> [a,b,c,d]=miltxy(3,8)
a =
11
b =
-5
c =
24
d =
0.3750
Basic 2D Plotting
2D Plotting Options
Labels
Adding Legends
Line styles
The Axis Commands
Showing Multiple Functions on One Plot
Subplots
Polar and Logarithmic Plots
Labels -1تسمجات
االِص )٠ : (xlabelػزؼًّ الظبفخ رػّ١خ ٌٍّؾٛش االفم. ٟ
)'xlabel('horizontal
االِص )٠ : (ylabelػزؼًّ الظبفخ رػّ١خ ٌٍّؾٛش اٌؼّٛذ. ٞ
;]>> x = [0:0.05:2
;)>> y = sinh(x
)'*>> plot(x,y,'r
Showing Multiple Functions on One Plot رسم عدة دوال ضمن رسم بجانً واحد
: خ١ٌزٌه ثبؽر اٌطصائك اٌزبٚ اؽرحٚ خ١ٔب١ؽخ شغُ ثٌٛ ّٓخ ظ١بظ٠اي شِٚبد ٌرٛبش ػرح شغّٙىٓ اظ٠
>> x=[-1:0.01:3];w=[1:0.02:4];
>> plot(x,exp(x)-12,w,4-w.^2),legend('y=e^x-12','z=4-w^2',2)
>> x = [0:0.1:20];
>> y = exp(–10*x.^2);
>>loglog(x,y,'r','LineWidth',3),grid on,title('y=exp(-10x^2)')
>> x = [0:0.1:20];
>> y = exp(–10*x.^2);
>> semilogy(x,y,'r','LineWidth',3),grid on
>> semilogx(x,y,'r','LineWidth',3),grid on
االِص )٠ : (solveػزؼًّ ٌؾً اٌّؼبذالد ِٓ ا ٞذشعخ وبٔذ ذ ثبالظبفخ اٌ ٝاغزدراِبرٗ االخص.ٜ
)'solve('equation','var
ِضبي : 1ثبغزدراَ MATLABعر ؽً اٌّؼبذٌخ اٌزبٌ١خ اٌراٌخ اٌزبٌ١خ
x 3 0
)'>> solve('x-3=0') or solve('x-3') or solve('x-3','x
= ans
3
)'>> x=solve('x-3
= x
3
)'>> s = solve('x^2-6*x-12
= s
)3 - 21^(1/2
21^(1/2) + 3
ٔػزدرَ االِص doubleالظٙبش إٌزبئظ ثص ١خ ػشص٠خ
)>> x=double(s
= x
-1.5826
)')>> s = solve('(x+1)^2*(x-2
= s
-1
-1
2
))'>> x = double(solve('x^3-6*x^2-72*x-27
= x
12.1229 - 0.0000i
-5.7345 - 0.0000i
-0.3884 + 0.0000i
C Derivation, Integration
and Differential Equation
Derivation
Integration
Differential equation
>> g1=diff(g)
g1 =
(-10)*cos(10*t)
>> g2=diff(g,2)
g2 =
100*sin(10*t)
>> subs(g2,{t},{4})
ans =
74.5113
>> z1=diff(z,y)
z1 =
3*x*y^2 + sin(x)
>> z2=diff(z,x,2)
z2 =
2 - y*sin(x)
x sin xdx
1
>> syms x
>> int(1/(1+exp(x)))
ans =
x - log(exp(x) + 1)
>> s=int(x*sin(x),1,5)
s =
cos(1) - 5*cos(5) - sin(1) + sin(5)
>> double(s)
ans =
-2.67843
x 5 y xy 3dydx
2
>> syms x y
>> s1=int(int(x^2+5*y+x*y^3,x),y)
s1 =
(x*y*(8*x^2 + 3*x*y^3 + 60*y))/24
s2 =
(x*y*(8*x^2 + 3*x*y^3 + 60*y))/24
0
r sin drd
>> A=double(h)
A =
-2.6015
0 1 0
dzdydx
>> syms x y z
>> V=int(int(int(1,z,0,1+y^2),y,-1,x^2),x,0,3)
V =
820/7
>> double(V)
ans =
117.1429
>> dsolve('Dy=a*y')
ans =
C1*exp(a*t)
Lecturer: Mr. Munther R.
50
خ١ٌخ اٌزب١ٍاي اٌزفبظٚ عر ؽً اٌرMATLAB َ ثبغزدرا: 7 ِضبي
dy x
y , y (0) 2
dx x 5
d 2y
y 0, y (0) 1 y '(0) 2
dx 2
>> dsolve('Dy=y*x/(x-5)','y(0)=2','x')
ans =
-(2*exp(x + 5*log(x - 5)))/3125