.


:




:

































 

 

 

 


,

. . .

 

 

 

Matlab

. .

10-22

 

 

2012

 

:

1. 1... 2

2. 2 4

3. 3, 4, 512

4. 616

5. 720

6. 826

7. 934

8. 䅅36

9. .37

 

 

1

:

.

y = f (x), 0 .

 

: 0=3,1

 

:

x = 0:0.05:1;

y = sec(x) + sin (x) -1;

plot (x, y)

x0=3.1

y0 = sec(x0) + sin (x0) -1

 

:

 

 

:

 

 

 

2

 

: .

  1. [0.01, 2π]:

:

;

;

.

, , , , , .

:

x = 0.01:0.01:2*pi;

y = sqrt(x) -1-cos(0.5*x);

f = exp(-x).* sqrt(1+x+x.^2) - (x.^2);

plot (x, y, x, f) %

plotyy (x, y, x, f) % ( )

subplot(1,2,1); plot(x,f) %

subplot(1,2,2); plot(x,y)

figure; plot (x,y) %

figure; plot (x,f)

plot (x, y, 'Y.-', x, f, 'm*--') % ,

grid on

title (' ')

legend (' 1',' 2')

xlabel (' ')

ylabel (' ')

 

:

 

 

% ( )

,

 

 

2.

:

;

;

( , );

.

. .

:

[x, y] = meshgrid (-1:0.05:1, -1:0.05:1);

z=(((sin(x.^2)) + (cos(x.^2))).^(x*y));

mesh (x, y, z) %

surf(x, y, z) %

colorbar

surfc(x, y, z) %

colorbar

surfl (x, y, z) %

subplot(2,3,1); mesh (x, y, z)

title (' ')

subplot(2,3,2); surf(x, y, z)

colorbar

title (' ')

subplot(2,3,3); surfc(x, y, z)

colorbar

title (' ')

subplot(2,3,4); surfl (x, y, z)

title (' ')

subplot(2,3,5); mesh (x, y, z)

title (' ()')

subplot(2,3,6); surf(x, y, z)

colorbar

title (' ()')

// ,

 

:

:

3. .

( ):

;

;

:

:

[x, y] = meshgrid (-5:0.05:5, -5:0.05:5);

z=sqrt((x.^2) + (y.^2) +1);

f= ((x.^2)/8 +(y.^2)/8);

subplot(3,2,1); plot3 (x, y, z)

title(' ')

subplot(3,2,2); plot3 (x, y, f)

title(' ')

n = 0:0.5:3;

m = 0:0.5:3;

b = cos(n).*cos(m);

c = sin(n).*sin(m);

d = m.*n;

subplot(3,2,3); plot3 (m, n, b)

grid on

subplot(3,2,4); plot3 (m, n, c)

grid on

subplot(3,2,5); plot3 (m, n, d)

grid on

:

:

3,4,5

: MATLAB

:

- . , , : , find .

 

1. , .

:

function c = fun1(a)

disp(prod(find(a <(mean(a)))));

:

2. .

:

function c = fun2(A)

disp(sum(sum(A==0)))

disp(sum(sum(A==1)))

:

3. , .

:

function c = fun3(a)

i=find(a == max(a));

j=find(a == min(a));

disp(sum((a(j:i)>0)) -2);

end

 

:

4. , .

:

function c = fun4(a)

disp(sum(sum(find(triu(a)<0))));

end

:

5. .

:

function c = fun5(a)

a(a > 0) = sum(a(a < 0));

c=disp(a);

:

6. , :

:

function c = fun6(A)

clc

clear

n=input(' ');

for i=1:n

for j=1:n

if i>j

A(i,j)=i-j;

end

if i==j

A(i,j)=i+j;

end

if i<j

A(i,j)=i^2+j^2;

end

end

end

display(A)

:

7. :

:

function c = fun7(m,n)

syms x a b

c=symsum(symsum(((x^(a+b))/((a+b)^2)),b,1,m),a,1,n);

disp(c);

:

8. m :

:

function c = fun8(A)

c=sum(prod(A),2);

disp(c)

:

9. , 100:

:

function c = fun9(x)

s=0;

k=0;

while s<=100

k=k+1;

u=k*(x.^k);

s=s+u;

end

n=k;

display(n);

:

10. :

ε. , .

, s(x) .

:

function c =fun10()

clc

N = 10;

eps = 1e-12;

eps_current = 1;

a = 1;

mysum = @(a,x) sum(a.^(1:x)./ cumprod(1:x));

S = mysum(a, N);

while(eps_current > eps)

S_old = S;

N = 2 * N;

S = mysum(a, N);

eps_current = (S - S_old) / S_old;

end

:

11. , , r. . , , , , .

:

function c= fun11(x_center,y_center,R,x1,x2)

fi = 0:0.01:2*pi;

x = x_center + R * cos(fi);

y = y_center + R * sin(fi);

plot(x,y)

hold on

plot(x1,x2,'.r');

hold off

 

 

// - , 3 4 5

 

6

: -

.

1. - , , . . -. fpiot plot :

;

;

:

-:

x=0:0.1:2*pi;

u=(sin(log(x+1))+cos(log(x+1)));

subplot(2,2,1)

plot(x,u)

title('u')

grid on

x=-0.9:0.1:0.9;

f=1./(1+(1./(1+x)));

subplot(2,2,2)

plot(x,f)

title('f')

grid on

x=0.5:0.1:1.5;

g=x.^(x.^x);

subplot(2,2,3)

plot(x,g)

title('g')

grid on

x=0:0.1:1;

h=sin(6*pi.*(x.^2).*abs(x-(2/3)));

subplot(2,2,4)

plot(x,h)

title('g')

grid on

 

:

2. - .

-:

:

-:

x=-1:0.1:1;

y=-1:0.1:1;

[X,Y]=meshgrid(x,y);

z=exp(3*X.*sin(Y.*pi*0.5)) + exp(3*Y.*sin(X.*0.5*pi));

subplot(1,2,1)

surf(X,Y,z)

title('Z')

grid on

x=0:0.1:1;

y=0:0.1:1;

[X,Y]=meshgrid(x,y);

w=(sin(exp(X.*2)-exp(Y.*(-2)))+cos(exp(Y.*2)-exp(X.*-2)));

subplot(1,2,2)

surf(X,Y,w)

title('W')

grid on

 

 

:

 

2. - :

 

1) ;

 

function c = function1(a)

[ maxVal maxInd ] = max(abs(a - mean(a)));

 

2) ;

 

function b = summa(a,m,n)

a=m:2:n;

b= sum(a);

 

3) ;

 

function c = function3(A)

c = max(diag(A))

 

4) ;

function b =function4(A)

v = diag(A);

A=diag(A(:,1));

A(:,1)= v;

b=A;

 

5) ;

 

function S =sum(A)

S = sum(sum(A)) - sum(diag(A));

 

 

6) ;

 

function x = replaceMax2Mean(x)

x(x == max(x)) = mean(x);

 

7) 1,1 ;

 

function ans = proizv(A)

A (1,1) = prod(prod(A));

 

8) () (xi9yi),

;

 

function z= function8(X,Y)

X=[1 2 3 2 1];

Y=[1 2 0 5 1];

z=patch(X,Y,[1 0 0]);

 

9) , .

 

function c = function9(a)

I=max(a);

i=find(a == max(a));

disp(i);

disp(I);

plot(a,'.b');

hold on

plot(a(i),'.r');

hold off

end

 

 

// - , 6

 

 

7

: MATLAB

1. :

, [0, 4].

:

fplot ('(cos (x - sqrt(2)).*exp(2*sin (x))-1)', [0,4])

grid on

x1 = fzero ('(cos (x - sqrt(2)).*exp(2*sin (x))-1)', 0.5)

x2 = fzero ('(cos (x - sqrt(2)).*exp(2*sin (x))-1)', 2.5)

I = quad ('(cos (x - sqrt(2)).*exp(2*sin (x))-1)', x1, x2)

:

:

2.

, [-5, 0].

:

fplot ('sin(x) - (x.^2).* cos (x)', [-5,0])

grid on

x1 = fminbnd ('sin(x) - (x.^2).* cos (x)', -4, -3.5)

x2 = fminbnd ('sin(x) - (x.^2).* cos (x)', -1.5, -1)

I = quad ('sin(x) - (x.^2).* cos (x)', x1, x2)

:

:

:

f(z) = 0.1,

:

syms x

f = x.* tan(x).^2;

integral=int (f, x)

c = log(cos(0)) + 0*tan(0) - 0^2/2

% - d= f(z)-f(0) .. = f(0)=0, d = f(z)

syms z

d = log(cos(z)) + z*tan(z) - z^2/2

fplot ('log(cos(z)) + z*tan(z) - z^2/2-0.1', [-10,10])

% f(z) = 0.1

grid on

% , ,

 

:

:

 

:

4. [0, 5]:

:

-:

function F = ddefun(x,y,Z)

Y1 = Z(:,1);

Y2 = Z(:,2);

F = [ Y2(1)

-Y1(2)+Y2(1)];

 

function S = ddehistory(x)

S = [(sin(x) + 0.1)

(x -2)];

 

function ddetest

sol =dde23(@ddefun,[0.5; 1], @ddehistory,[0, 5]);

figure

subplot (2,1,1)

plot (sol.x, sol.y(1,:), 'o')

y1= inline ('sin(x) + 0.1');

hold on

fplot (y1, [0,5], 'r')

title (' ')

legend (' ',' ')

subplot (2,1,2)

plot (sol.x, sol.y(1,:), '+')

y2 = inline('x-2');

hold on

fplot(y2, [0,5], 'r')

title (' ')

legend (' ', ' ')

 

// ,

 

:

:

 

:

5.

:

-:

 

function solvdem

Y0=[0.02;1];

[T,Y]=ode113(@oscil,[0;5],Y0);

plot(T,Y(:,1),'r.-')

hold on

plot(T,Y(:,2),'k.:')

grid on

hold off

 

function F = oscil(x,y)

F= [y(2); 0.1*(y(1)^2)-3*y(1) + 2*sin(x)];

 

:

// - , 7

 

8

1.

aik. n (, 3, ) ( ):

:

A= [ -1.2 4.6 -0.3

2.8 9.9 -0.7

0.9 -2.5 7.1]

n=size(A)

S = sum (A)

S = sum (S)

p = sum (max(A))

q = sum (max (A, [ ], 2))

:

2. ,

, , ,

:

;

 

 

;

:

d = [ 2 3 4 5 6 7 8]

N = diag (d) + diag (ones (1, 6), 1) + diag (ones (1,6), -1) + diag ((5), 6) + diag ((5), -6)

N (6,7) = 0

 

:

:

A = eye(7) + rot90(-eye(7))

A (4,4) = 5

:

:

A = diag(ones (1,7),4) + eye (11,11)

A (8:11,:) = [ ]

 

:

:

A = eye (11,11) + diag (ones (1,10),1)

D = diag (-1*ones(1,10),1)

D (:, 5:end) = 0

B = -1*eye(11)

B (1:3,:) = 0

S = A + D + B

 

:

3. ( ) , .

; ;

;

:

M= [ eye(3) 4*eye(3); 2*ones(3) 3*ones(3)]

S= sum(sum (sqrt(M^2)))

 

N = [ ones(2) -3*ones(2,4); -3*ones(4,2) 2*eye(4)]

:

 

 

1) .

:

[V, ind] = sort(sum(A))

A = A ([ ind],:)

:

 

2) .

:

N = max (A, 0)

S = sum(sum (N))

:

 

3) matr.txt ( ),

, , newmatr.txt ( )

:

A = load ('matr.txt')

Sr = mean(mean (A))

S = max (A, Sr)

save ' newmatr.txt ' S -ascii

:

 

4) .

:

[ i, j ] = max(find (A<0))

:

9

:

2. Property Editor, :

;

;

;

:

[x, y] = meshgrid (-5:0.05:5, -5:0.05:5);

z=sqrt((x.^2) + (y.^2) +1);

f= ((x.^2)/8 +(y.^2)/8);

b = ((x.^2)/8 -(y.^2)/8);

surf(x,y,z)

surf(x,y,f)

surf(x,y,b)

:

 

:

, , . , , , . , . , . matlab , . , . , matlab .

:

1. ., ., . MATLAB 7.0. - 2005.

2. http://solidbase.karelia.ru/edu/meth_calc/files/sod.shtm

3. http://matlab.exponenta.ru/



<== | ==>
| . . : .
:


: 2016-12-18; !; : 1842 |


:

:

, .
==> ...

1607 - | 1440 -


© 2015-2024 lektsii.org - -

: 0.308 .