<< Chapter < Page Chapter >> Page >
  • Cách1:

>>a=1;

>>b=-4;

>>c=5

>>x1=(-b+sqrt(b^2-4*a*c))/(2*a)

>>x2=(-b-sqrt(b^2-4*a*c))/(2*a)

  • Cách 2:

>>m=[a b c];

>>x=roots(m)

Hãy thay đổi các giá trị khác nhau của a, b và c tương ứng trong 2 cách giải trên. So sánh kết quả và nhận xét.

Giải phương trình x3- 2x2+4x+5=0. Kiểm chứng kết quả thu được bằng hàm polyval. Sinh viên có nhận xét gì về kết quả kiểm chứng.

Lặp lại câu  cho phương trình x7-2=0.

Sinh viên thử dùng hàm poly để tạo đa thức từ các nghiệm cho trước.

>>help poly

Đồ họa

Matlab hổ trợ chế độ đồ họa rất mạnh, bao gồm đồ họa 2D và 3D, với các trục tọa độ tuyến tính và phi tuyến bất kỳ.

Đồ họa 2 d

Đồ họa 2D chủ yếu dựa trên lệnh plot. Để được giúp đỡ, ta gõ:

>>help plot

Vẽ đồ thị hàm số y1=sinx.cos2x và hàm số y2=sinx2 trong [0-2], trên cùng hệ trục tọa độ, ta lần lượt thực hiện như sau:

>>x=0:0.01:2*pi;

>>y1=sin(x).*cos(2*x);%nhan tuong tung tung phan tu

>>plot(x,y1)

>>grid on%hien thi luoi

Sau khi thu được đồ thị hàm y1, để vẽ y2 trên cùng đồ thị, ta thực hiện:

>>hold on%giu hinh, mac nhien la hold off

>>y2=sin(x.^2);%luy thua tung phan tu

>>plot(x,y2,’k’)%duong ve co mau den

>>axis([0 4*pi –1.25 1.25])%dinh lai toa do hien thi

Ta có thể đặt nhãn cho các trục cũng như tiêu đề cho đồ thị:

>>xlabel(‘Time’)

>>ylabel(‘Amplitude’)

>>title(‘y1=sinx.cos2x and y2=sin(x^2)’)

>>legend(‘sinx.cos2x’,’sinx^2’)

Hình 1.1 – Biểu diễn đồ thị các hàm số trên cùng hệ trục tọa độ

Matlab hổ trợ rất nhiều thuộc tính đồ họa, để có thể kiểm soát các thuộc tính này ta cần dùng đến thẻ đồ họa. Ví dụ:

>>close all

>>x=[0 1 2 3];

>>y=[0 4 1 5];

>>h=plot(x,y)

h chính là thẻ đồ họa của hàm plot, để thấy các thuộc tính đồ hoạ, ta dùng lệnh:

>>set(h)

Bây giờ ta thử đặt một số thuộc tính đồ họa cho h.

>>set(h,’Color’, ‘r’)%dat lai mau do

>>set(h,'LineWidth',6)%dat do rong duong

>>set(h,'Marker','v','MarkerSize',6)

Hình 1.2 – Thay đổi thuộc tính đường biểu diễn

Dữ liệu dùng để vẽ được đặt trong ‘XData’ và ‘YData’.

>>set(h,'XData',[0 1 1 3])

>>set(h,'YData',[0 3 5 1])

Từ kết quả này, ta nhận thấy nếu dữ liệu trong ‘XData’ và ‘YData’ biến thiên theo thời gian, thì trên cửa sổ đồ họa (figure) ta sẽ thấy hình ảnh sinh động kiểu ‘animation’.

Hình 1.3 - Thay đổi dữ liệu trong cửa sổ đồ họa

Tương tự như hàm plot, sinh viên thử dùng các hàm semilogx, semilogy và loglog cho trường hợp trục tọa độ phi tuyến.

Ngoài các lệnh biểu diễn đường cong trong tọa độ Descartes, Matlab cũng hổ trợ việc vẽ đồ thị hàm số trong hệ tọa độ cực bằng hàm polar.

>>theta=0:0.05:2*pi;

>>r=sin(5*theta);

>>polar(theta,r)

Hình 1.4 – Biểu diễn đồ thị hàm số trong hệ tọa độ cực

Đồ họa 3 d

Matlab cung cấp nhiều hàm vẽ đồ thị 3D, chẳng hạn: plot3 - dùng để vẽ các đường trong không gian 3 chiều; mesh và surf - dùng để vẽ vật thể 3D (gõ help mesh và help surf để biết thêm các hàm 3D có liên quan).

Vẽ đồ thị 3D bằng hàm plot3:

>>t=0:pi/50:10*pi;

>>x=sin(t);

>>y=cos(t);

>>z=t;

>>subplot(121), plot3(x,y,z)%ve tren o thu nhat

>>grid on

>>subplot(122), plot3(x,y,t.^2)%ve tren o thu hai

>>grid on

Hình 1.5 – Vẽ đồ thị 3D bằng hàm plot3

Vẽ mặt paraboloid z=x2+y2 trong không gian 3 chiều:

>>close all

>>t=-5:0.1:5;

>>[x,y]=meshgrid(t);%dinh luoi ve

>>z=x.^2+y.^2;

>>subplot(2,2,1), mesh(z)%ve mat luoi 3D

>>title('mesh(z)')

>>subplot(2,2,2), meshc(z)%giong mesh nhung co them duong vien

>>title('meshc(z)')

>>subplot(2,2,3), meshz(z)%co them luoi tren mat x,y

>>title('meshz(z)')

>>subplot(2,2,4), waterfall(z)%chi ve luoi theo 1 huong

>>title('waterfall(z)')

***SORRY, THIS MEDIA TYPE IS NOT SUPPORTED.***

Hình 1.6 - Vẽ mặt paraboloid

Vẽ mặt z = sin x 2 + y 2 x 2 + y 2 size 12{z= { {"sin" left ( sqrt {x rSup { size 8{2} } +y rSup { size 8{2} } } right )} over { sqrt {x rSup { size 8{2} } +y rSup { size 8{2} } } } } } {} trong không gian 3 chiều:

>>x=-8:0.5:8;

>>y=x;

>>[x,y]=meshgrid(x,y);

>>r=sqrt(x.^2+y.^2);

>>z=sin(r)./r;

>>surf(x,y,z)

Hình 1.7 – Một biểu diễn đồ thị 3D khác

Sinh viên thử vẽ mặt trụ z = x 4 + y 2 size 12{z= sqrt {x rSup { size 8{4} } +y rSup { size 8{2} } } } {} bằng hàm mesh và hàm surf.

Tự chọn

Giải hệ phương trình sau:

2x1+4x2+6x3 – 2x4=0

x1+2x2+ x3 + 2x4=1

2x2+4x3 + 2x4=2

3x1- x2+ 10x4=10.

Chứng tỏ rằng (A+B)C=AC+BC, với:

A= 10 2 20 4 3 6 size 12{ left [ matrix { "10" {} # - 2 {} ##"20" {} # 4 {} ## 3 {} # 6{}} right ]} {} , B= 3 1 10 2 0 5 size 12{ left [ matrix { 3 {} # 1 {} ##- "10" {} # 2 {} ## 0 {} # 5{}} right ]} {} và C= 3 4 6 1 size 12{ left [ matrix { - 3 {} # 4 {} ##6 {} # 1{} } right ]} {} .

Sinh viên thử vẽ hình sau (Hình 1.8):

***SORRY, THIS MEDIA TYPE IS NOT SUPPORTED.***

(Hình 1.8)

Từ cửa sổ lệnh của Matlab, nhập: demos. Chọn MATLAB  Graphics  3D-plots. Chạy chương trình demo này.

Questions & Answers

calculate molarity of NaOH solution when 25.0ml of NaOH titrated with 27.2ml of 0.2m H2SO4
Gasin Reply
what's Thermochemistry
rhoda Reply
the study of the heat energy which is associated with chemical reactions
Kaddija
How was CH4 and o2 was able to produce (Co2)and (H2o
Edafe Reply
explain please
Victory
First twenty elements with their valences
Martine Reply
what is chemistry
asue Reply
what is atom
asue
what is the best way to define periodic table for jamb
Damilola Reply
what is the change of matter from one state to another
Elijah Reply
what is isolation of organic compounds
IKyernum Reply
what is atomic radius
ThankGod Reply
Read Chapter 6, section 5
Dr
Read Chapter 6, section 5
Kareem
Atomic radius is the radius of the atom and is also called the orbital radius
Kareem
atomic radius is the distance between the nucleus of an atom and its valence shell
Amos
Read Chapter 6, section 5
paulino
Bohr's model of the theory atom
Ayom Reply
is there a question?
Dr
when a gas is compressed why it becomes hot?
ATOMIC
It has no oxygen then
Goldyei
read the chapter on thermochemistry...the sections on "PV" work and the First Law of Thermodynamics should help..
Dr
Which element react with water
Mukthar Reply
Mgo
Ibeh
an increase in the pressure of a gas results in the decrease of its
Valentina Reply
definition of the periodic table
Cosmos Reply
What is the lkenes
Da Reply
what were atoms composed of?
Moses Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Thí nghiệm cad (computer-aided design). OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10797/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Thí nghiệm cad (computer-aided design)' conversation and receive update notifications?

Ask