Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
матлаб.docx
Скачиваний:
3
Добавлен:
13.09.2019
Размер:
1.01 Mб
Скачать

Построение таблицы значений функции

>> x=[0.3 0.6 0.9 1.4 1.8 2.6];

>> y=sin(x).^2./(1+cos(x)+exp(-x).*log(x));

>> y=sin(x)^2./(1+cos(x)+exp(-x).*log(x));

??? Error using ==> mpower

Matrix must be square.

>> x

x =

0.3000 0.6000 0.9000 1.4000 1.8000 2.6000

>> y

y =

0.0821 0.2064 0.3887 0.7751 1.0901 1.2413

>> x=[1, 1.3, 1.5, 1.6, 1.9, 2.1]

x =

1.0000 1.3000 1.5000 1.6000 1.9000 2.1000

>> x=[1:-0.2:-2]

x =

Columns 1 through 8

1.0000 0.8000 0.6000 0.4000 0.2000 0 -0.2000 -0.4000

Columns 9 through 16

-0.6000 -0.8000 -1.0000 -1.2000 -1.4000 -1.6000 -1.8000 -2.0000

>> x=[1:0.2:2]

x =

1.0000 1.2000 1.4000 1.6000 1.8000 2.0000

>> x=(0:0.1:00.5)'

x =

0

0.1000

0.2000

0.3000

0.4000

0.5000

>> x=1:5

x =

1 2 3 4 5

>> x=0:0.05:1;

>> y=exp(-x).*sin(10*x);

>> x

x =

Columns 1 through 8

0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500

Columns 9 through 16

0.4000 0.4500 0.5000 0.5500 0.6000 0.6500 0.7000 0.7500

Columns 17 through 21

0.8000 0.8500 0.9000 0.9500 1.0000

>> y

y =

Columns 1 through 8

0 0.4560 0.7614 0.8586 0.7445 0.4661 0.1045 -0.2472

Columns 9 through 16

-0.5073 -0.6233 -0.5816 -0.4071 -0.1533 0.1123 0.3262 0.4431

Columns 17 through 21

0.4445 0.3413 0.1676 -0.0291 -0.2001

>> [x' y']

ans =

0 0

0.0500 0.4560

0.1000 0.7614

0.1500 0.8586

0.2000 0.7445

0.2500 0.4661

0.3000 0.1045

0.3500 -0.2472

0.4000 -0.5073

0.4500 -0.6233

0.5000 -0.5816

0.5500 -0.4071

0.6000 -0.1533

0.6500 0.1123

0.7000 0.3262

0.7500 0.4431

0.8000 0.4445

0.8500 0.3413

0.9000 0.1676

0.9500 -0.0291

1.0000 -0.2001

Построение графиков функции одной переменной

>> x=0:0.5:1;

>> y=exp(-x).*sin(10*x);

>> plot(x,y)

>> x=0:0.1:1;

>> y=exp(-x).*sin(10*x);

>> plot(x,y)

>> x=-1:0.5:-0.3;

>> f=sin(x.*-2);

>> g=(1.4*x.^-3);

>> plot(x,f,x,g)

>> plot(x,f,'k-',x,g, 'k:')

Умножение векторов

>> a=[1.3; -4.3; 0.9];

>> b=[4.3; 6.7; -2.9];

>> s=sum(a.*b)

s =

-25.8300

>> s=dot(a,b)

s =

-25.8300

>> d=sqrt(dot(a,a))

d =

4.5815

>> a=[1.2; -3.7; 0.9];

>> b=[4.2; 6.1; -2.5];

>> c=cross(a,b)

c =

3.7600

6.7800

22.8600

>> cross(a,b)+cross(b,a)

ans =

0

0

0

>> a=[3.6; 0; 0];

>> b=[0.3; 2.5; 0];

>> c=[-0.3; -1.2; 2.6];

>> v=abs(dot(a, cross(b,c)))

v =

23.4000

>> a=[1; 2; 3];

>> b=[5; 6; 7];

>> c=a*b'

c =

5 6 7

10 12 14

15 18 21

Двумерные масивы часть 1/2

>> a=[3 1 -1; 2 4 3];

>> b=[4 3 -1

2 7 0

-5 1 2]

b =

4 3 -1

2 7 0

-5 1 2

>> c=[[3; 4] [-1; 2] [7; 0]]

c =

3 -1 7

4 2 0

>> whos

Name Size Bytes Class Attributes

a 2x3 48 double

ans 1x1 8 double

b 3x3 72 double

b1 2x2 32 double

b2 3x3 72 double

c 2x3 48 double

d 2x1 16 double

f 2x1 16 double

i1 3x1 24 double

ind 3x3 9 logical

ind1 3x3 72 double

ind2 3x3 9 logical

j1 3x1 24 double

k 1x1 8 double

km 1x3 24 double

m 1x1 8 double

n 1x2 16 double

p 2x3 48 double

r 2x3 48 double

s 2x3 48 double

x 1x8 64 double

xm 1x3 24 double

>> c(2,3)

ans =

0

>> c(1,1) +c(2,2)+c(2,3)

ans =

5

>> n=[1 2];

>> m=[2 3];

>> b1=b(n, m)

b1 =

3 -1

7 0

>> c(5)

ans =

7

>> ind=b<0

ind =

0 0 1

0 0 0

1 0 0

>> f=b(ind)

f =

-5

-1

>> f=b(b<0)

f =

-5

-1

>> ind1=[0 0 1; 0 0 0; 1; 0 0];

??? Error using ==> vertcat

CAT arguments dimensions are not consistent.

>> ind1=[0 0 1; 0 0 0; 1 0 0];

>> b(ind1)

??? Subscript indices must either be real positive integers or logicals.

>> ind2=logical(ind1);

>> x=[1 2 5 3 4 5 1 5];

>> [m, k]=max(x)

m =

5

k =

3

>> xm=x(x==5)

xm =

5 5 5

>> km=find(x==5)

km =

3 6 8

>> [i1, j1]=find(b<=0)

i1 =

3

1

2

j1 =

1

3

3

>> k=find(b<=0)

k =

3

7

8