آموزش متلب

ترسیم توابع و منحنی های تراز در متلب

ترسیم توابع دو متغیره و سه متغیره و منحنی های تراز

 

ترسيم توابع عددي دو متغيره

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006036

> x=-1:.1:1;
>> y=0:.1:4;

>> [X,Y]=meshgrid(x,y);
>> f=inline(’10*x.^2+y.^2′,’x’,’y’)
f =
Inline function:
f(x,y) = 10*x.^2+y.^2
>> surf(X,Y,f(X,Y))

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006037

– راه كوتاه : ابتدا محدوده صفحه X-Y را در corners وارد مي كنيم.

 

>> clear
>> f=inline(’10*x.^2+y.^2′,’x’,’y’)
f =
Inline function:
f(x,y) = 10*x.^2+y.^2
>> corners=[-1 1 0 4];
>> qsurf(f,corners)

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006038

ملاحظه مي گردد كه mesh بندي دقيقتر است.

 

ترسيم توابع دو متغيره با مختصات قطبي

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006045

>> %first make a meshgrid in r,theta-coordinates
>> r=linspace(0,2,21);
>> thetta=linspace(0,2*pi,41);
>> [R,TH]=meshgrid(r,thetta);
>> %now convert into a curvlinear
>> X=1+R.*cos(TH);
>> Y=3+R.*sin(TH);
>> Z=X-1+Y.^2;
>> surf(X,Y,Z)
>> %add the plane Z=-5
>> hold on
>> surf(X,Y,-5+0*Z)
>> hold off

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006039

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006046

>> r=linspace(0,1,21);
>> thetta=linspace(0,2*pi,41);
>> [R,TH]=meshgrid(r,thetta);
>> X=R.*cos(TH);
>> Y=R.*sin(TH);
>> Z=0.5*R.*sin(TH)+R.^3.*cos(3*TH);
>> surf(X,Y,Z)

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006040

منحنيهاي تراز

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006047

>> x=-2:.05:2;
>> y=-2:.05:3;
>> [X,Y]=meshgrid(x,y);
>> f=inline(‘-6*exp(-3*x.^2-y.^2)+.5*x+y’,’x’,’y’);
>> Z=f(X,Y);
>> pcolor(X,Y,Z)
>> hold on
>> contour(X,Y,Z,10,’k’)
>> hold off

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006041

 

تكنيك رسم سريع توابع دو متغيره

تابع بالا را رسم ميكنيم:

> syms x y
>> f=-6*exp(-3*x^2-y^2)+.5*x+y;
>> ezsurf(f)

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006042

رسم بردار گراديان و منحني تراز

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006048

>> f=inline(‘x.*y-(x.^3)/3′,’x’,’y’);
>> fx=inline(‘y-x.^2′,’x’,’y’);
>> fy=inline(‘x’,’x’,’y’);
>> x=-2:0.05:2;
>> y=x;
>> [X,Y]=meshgrid(x,y);
>> Z=f(X,Y);
>> levels=[-6:0.5:6];
>> contour(X,Y,Z,levels)
>> hold on
>> xx=-2:0.2:2;
>> yy=xx;
>> [XX,YY]=meshgrid(xx,yy);
>> U=fx(XX,YY);
>> V=fy(XX,YY);
>> quiver(XX,YY,U,V)
>> axis equal

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006043

رسم سطوح تراز توابع سه متغيره

همان طور كه مي دانيم معادله سطوح تراز به صورت f(x,y,z)=c مي باشد. اين ترسيم به كمك M-File اي
به صورت (impl(f,corners,c انجام مي شود.

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006049

> f=inline(‘x.^2+y.^2-z.^2′,’x’,’y’,’z’);
>> corners=[-4 4 -4 4 -4 4];
>> subplot(2,2,1)
>> impl(f,corners,0)
ans =
The max over this domain is 32.00000
ans =
The min over this domain is -16.00000
>> subplot(2,2,2)
>> impl(f,corners,0.1)
ans =

The max over this domain is 32.00000
ans =
The min over this domain is -16.00000
>> subplot(2,2,3)
>> impl(f,corners,-0.5)
ans =
The max over this domain is 32.00000
ans =
The min over this domain is -16.00000
>> subplot(2,2,4)
>> impl(f,corners,1)
ans =
The max over this domain is 32.00000
ans =
The min over this domain is -16.00000

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006044

 

ترسيم ميدان برداري گراديان

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006050

> [X,Y]=meshgrid(0:0.4:2);
>> U=-X/2;
>> V=Y/2;
>> W=1+0*X;
>> subplot(1,2,1)
>> for z=[-1,0,1]
Z=z+0*X;
quiver3(X,Y,Z,U,V,W)
hold on
end
>> axis image
>> %plot the surface
>> [XX,YY]=meshgrid(0:0.05:2);
>> ZZ=0.25*(XX.^2-YY.^2);
>> subplot(1,2,2)
>> surf(XX,YY,ZZ)
>> shading interp
>> hold on

> %add the gradint vector
>> Z=0.25*(X.^2-Y.^2);
>> quiver3(X,Y,Z,U,V,W)
>> axis image

files.laitec.ir_wp-content_uploads_2013_09_matlab-tutorial_sarfaraz.pdf006051

سعید عربعامری
من سعید عربعامری نویسنده کتاب 28 گام موثر در فتح متلب مدرس کشوری متلب و سیمولینک و کارشناس ارشد مهندسی برق قدرتم . بعد از اینکه دیدم سایتهای متعدد یک مجموعه کامل آموزش متلب و سیمولینک ندارند به فکر راه اندازی این مجموعه شدم
http://sim-power.ir

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *