You are on page 1of 15

Bi 2: Mt s dng bi tp

Ni dung

Tnh ton vi cc biu thc n gin S dng help Tnh ton vi Ma trn v Vc t th

Tnh ton vi cc biu thc n gin

Cc phm , tin hoc lui lnh, , thay i v tr trn dng lnh // bt u ni dung ch thch

// The words after `//' are comments // and explanations. Do not type them in.

Chnh xc 16 ch s thp phn, nhng ch hin th 5 ch s thp phn

%pi 22/7 // pi is not the same as 22/7!


3

Tnh ton vi cc biu thc n gin

Cho php s dng bin cha gi tr trung gian


x = 2+3 y = 4+5 result1 = x/y p = 2+3 ; // The semicolons supress q = 3+5 ; // unwanted output. ratio = p/q
4

Du ; khng hin th kt qu

Tnh ton vi cc biu thc n gin

Du , v ; c dng vit nhiu lnh trn 1 dng

p = 2+3 ; q2 = x + 4 , ratio2 = p/q2 // All on one line

Du ng m ngoc () lm biu thc r rng hn

ratio = (2+3)/(x+4)

Tnh ton vi cc biu thc n gin


Php cng (+), tr (-), nhn (*), chia (/) Php tnh sin (sin), cosin (cos), logarith c s t nhin (log)... Hng s %pi, %i...

cos( %pi/3 ) // These are familiar trig functions. sin( %pi/6 ) // Note Scilab always uses radians.

Tnh ton vi cc biu thc n gin

S phc

%i=(-1)1/2 Cc hm abs(x), real(x), imag(x), atan(x)


x = 2 + 3*%i , y = 1 - 1*%i z1 = x - y , z2 = x * y , z3 = x / y abs( x ), real( x ), imag( x ) atan( imag(x) , real(x) ) // The argument of a complex number sin(x) // Scilab quickly calculates the sin of a complex number.
7

S dng help

C1: S dng help bng dng lnh vi c php: help <name>


help sin // Information about sin. help + // Gives links to help on Scilab operator names help log // This is enough information about log // to show log means log to the base e .

Ngoi ra apropos <name> cung cp thng tin lin quan

apropos logarithm // Provides a list of functions related to logarithms

S dng help

C2: S dng help qua menu C3: S dng help trn internet

http://www.scilab.org/product/man/

Tnh ton vi Ma trn v Vc t

Khi to ma trn, mi dng c ngn cch nhau bi ;, phn t

A = [ 1 2 -1; -2 -6 4 ; -1 -3 3 ] b = [ 1; -2; 1 ]

Cc hm khi to ma trn: ones, zeros, eye, rand...

c = ones(4,3), d = zeros(20,1), I = eye(5,5)


10

Tnh ton vi Ma trn v Vc t

Ly 1 phn ma trn c php: A( i:j, k:l )

A(2,3), A(1:2,2:4), A(:,2), A(3,:), A(2:$,$)

Cc php cng (+), tr (-), nhn (*), chia (/), tnh nh thc (det)...

A= [1 2 3 4 ; 1 4 9 16 ; 1 8 27 64 ; 1 16 81 256 ] A' det(A) spec(A) [D, X] = bdiag(A) inv(A) 11

Tnh ton vi Ma trn v Vc t

Xy dng a thc s dng hm poly()

v = [-4,-3,1], p = poly(v,'X','coeff') x = poly(0,'x') // Seed a Polynomial using variable 'x' p = x^2 - 3*x - 4 // Represents x^2 - 3 x -4

S dng cc hm tnh ton a thc nh root(), horner(), derivat()


z = roots( p ) z(1)^ 2 -3*z(1) -4 // Two ways to evaluate the poly. horner(p,z(1)) // at the first root. derivat(p,'x') // Calculate the derivative of the polynomial
12

th

V th 2 chiu, di dng im dng hm plot2d()


x = [.5 .7 .9 1.3 1.7 1.8 ]' y = [.1 .2 .75 1.5 2.1 2.4 ]' plot2d(x,y, style=-1) Ch thch: s dng help plot2d hiu thm v style

13

th

V th 2 chiu cho hm s dng deff() v fplot2d()


deff('[y]=f(x)',['y= x*abs(x)/(1+x^2)']); x = (-5:0.1:5)'; fplot2d(x,f)

V th theo trc logarith s dng plot2d1, plot2d2, plot2d3, plot2d4()

14

th
In th hoc lu th ra bo co

Bng cc chc nng tng ng trong menu File Hoc lu li cc dng to Graph di dng Text

15

You might also like