Вы находитесь на странице: 1из 34

MATLAB

1-

.
.
:
:
5 xy
1) r + tg 3k k = 1; r = 2; x = 2; y = 1
ln 2 x + 1 + 33 x x = 0,5
x+ y
x + 3y 3 x e
1
3)

+
x = 1; y = 2; z = 3
1
2z
x+ y
1+
1
1+
x
x
4) sin 3 + cos x 2 25 cos 3 x x = 0,3
2
2)

k=input('Input k: ');
r=input('Input r: ');
x=input('Input x: ');
y=input('Input y: ');
r1=abs(r)^(5*x*y)+tan(3*k);
disp('r1='); disp(r1);
x=input('Input x: ');
r2=sqrt(log(x)^2+1)+3*x^(1/3);
disp('r2='); disp(r2);
x=input('Input x: ');
y=input('Input y: ');
z=input('Input z: ');
u1=(x+3*y)/(2*z);
u2=3*abs(x)*exp(x+y)/(x+y);
r3=u1-u2;
u3=1/(1+1/(1+1/x));
r3=u1-u2+u3;
disp('r3='); disp(r3);
x=input('Input x: ');
r4=sin(x/2)^3+cos(x^2)-2*cos(3*x)^(1/5);
disp('r4='); disp(r4);


ax2+bx+c=0,
a = t - 1,

b=2t,

c=t+3

clc
t.
t=input('Input t: ');
a=t-1;
b=2*t;
c=t+3;
if a==0
x=-c/b;
disp('x='); disp(x);
else
d=b^2-4*a*c;
if d<0
disp(' ');
else
x1=(-b-sqrt(d))/(2*a);
disp('x1='); disp(x1);
x1=(-b+sqrt(d))/(2*a);
disp('x2='); disp(x2);
end
end

: u=max{x,y}, v=min{x,y)
clc
x=input('Input x: ');
y=input('Input y: ');
if x>y
u=x;
v=y;
else
u=y;
v=x;
end
fprintf('u=%d v=%d',u,v).

x,y

x>y
u=x
v=y

u=y
v=x

u,v

2- : u=max{x,y}, v=min{x,y)
clc
x=input('Input x: ');
y=input('Input y: ');
z=input('Input z: ');
u=min(x,y);
v=max(u,z);
fprintf('\nu=%1.3f',u);
fprintf('\nv=%1.3f',v);

x,y

x>y
u=x
v=y

u=y
v=x

u,v

: u=max{x,y,z}
clc
x=input('Input x: ');
y=input('Input y: ');
z=input('Input z: ');
if x>y
if x>z
u=x;
else
u=z;
end
else
if y>z
u=y;
else
u=z;
end
end
fprintf('u=%d',u)
:

x,y

x>y

x>z

u=x

u=z

u x,y,z.

y>z

u=y

, 5,
clc
x=input('Input x: ');
y=input('Input y: ');
z=input('Input z: ');
s=0;
if abs(x)<5
s=s+x;
else
fprintf('\nx=%f',x);
end
if abs(y)<5
s=s+y;
else
fprintf('\ny=%f',y);
end
if abs(z)<5
s=s+z;
else
fprintf('\nz=%f',z);
end
fprintf('\ns=%1.3f',s);

x,y,z
s=0

|x|<5
x

s=s+x

|y|<5
y

s=s+y

|z|<5
z

s=s+z

[-5,5]
F(x) = x4 + 4x3 - 6x2 + 12x - 1
clc
a0=input('Input a0: ');
a1=input('Input a1: ');
a2=input('Input a2: ');
a3=input('Input a3: ');
a4=input('Input a4: ');
x=-5:0.5:5;
y=a0+a1*x+a2*x.^2+a3*x.^3+a4*x.^4
fmax=max(y)
fmin=min(y)
plot(x,y); grid on;
xlabel('x'); ylabel('y');

( 1) k x k
s=
k!
k=1
N


N=10
X = 0.1; 0.3; 0.4; 0.7 1
clc
line='--------------------';
n=input('Input n: ');
nx=5;
for i=1:nx;
text = sprintf('Input x%d : ',i);
x(i)=input(text);
end

disp(line);
disp('|
disp(line);

|');

for i=1:nx
s(i)=0;
u=-x(i);
for k=1:n
s(i)=s(i)+u;
u=-u*x(i)/(k+1);
end
fprintf('|%8.4f |%8.4f |\n',x(i),s(i));
disp(line);
end

.
A(n).
(, ) Mas1.DAT.
length.
Mas1.DAT

Mas2.DAT

-2 3 0 4 0 1

123456

clc
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
disp('cc A');
disp('====================');
disp(A);
n=length(A);

:
clc
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
disp('cc A');
disp('====================');
disp(A);
n=length(A);
s=0; k=0;
for i=1:n
if A(i)>0
s=s+A(i);
k=k+1;
end
end
if k>0
s=s/k;
end
fprintf('\ns=%f',s);
fclose(fid);

: ()
clc
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
disp('cc A');
disp('====================');
disp(A);
n=length(A);
r=A(1); k=1;
for i=2:n
if A(i)>r
r=A(i);
k=i;
end
end
fprintf('\nk=%d\nr=%f',k,r);
fclose(fid);

:
clc
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
disp('cc A');
disp('====================');
disp(A);
n=length(A);
r=1e25; k=-1;
for i=1:n
if A(i)<=0
continue;
end
if A(i)<r
r=A(i);
k=i;
end
end
fprintf('\nk=%d\nr=%f',k,r);
fclose(fid);

: 0
clc
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
disp('cc A');
disp('====================');
disp(A);
n=length(A);
s=0; p=1;
for i=1:n
if A(i)==0
break;
else
p=p*A(i);
end
end
for j=i+1:n
s=s+A(j)
end
fprintf('\ns=%f\np=%f',s,p);
fclose(fid);

: ,

clc
fid = fopen('Mas2.dat');
A = str2num(fgetl(fid));
disp('cc A');
disp('====================');
disp(A);
n=length(A);
for i=1:2:n
A(i)=A(i)*2;
end
for i=2:2:n
A(i)=0;
end
disp(' cc A');
disp('====================');
disp(A);
fclose(fid);

: C :
C1=A1; C2=B1; C3=A2; C4=B2;
disp('cc B');
clc
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
fclose(fid);
disp('cc A');
disp('====================');
disp(A);
n=length(A);
fid = fopen('Mas2.dat');
B = str2num(fgetl(fid));
fclose(fid);

disp('====================');
disp(B);
C=zeros(1,2*n);
for i=1:n
C(2*i-1)=A(i);
C(2*i)=B(i);
end
disp(' cc C');
disp('====================');
disp(C)

: B ,
A
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
fclose(fid);
disp('cc A');
disp('====================');
disp(A);
n=length(A);
k=0;
for i=1:n
if A(i)>0
k=k+1;
B(k)=A(i);
end
end
for i=1:n
if A(i)<0
k=k+1;
B(k)=A(i);
end
end

disp(' cc B');
disp('====================');
disp(B)

:
clc
fid = fopen('Mas1.dat');
A = str2num(fgetl(fid));
disp('cc A');
disp('====================');
disp(A);
n=length(A);
for i=1:fix(n/2)
r=A(i);
A(i)=A(n+1-i);
A(n+1-i)=r;
end
disp(' cc A');
disp('====================');
disp(A);
fclose(fid);

: s=(ABp+q,r)
.

1 2 3
A = 1 2 1

3 2 0

4 1 2
B = 0 4 3

1 1 1

.
01
p = 1.7

15
.

LINALG.DAT
123121320
412043111
0.1 1.7 -1.5
-1.6 0.8 1.1
-1.7 1.3 0.2

.
16
q = 0.8

11
.

0.7
r = 13
.

0.2

clc
fid = fopen('Linalg.dat');
A = str2num(fgetl(fid));
disp(' A');
A=reshape(A,3,3);
A=A';
disp('====================');
disp(A);
B = str2num(fgetl(fid));
disp(' B');
B=reshape(B,3,3);
B=B';
disp('====================');
disp(B);
p = str2num(fgetl(fid));
disp(' P');
disp('====================');
disp(p);

q = str2num(fgetl(fid));
disp(' Q');
disp('====================');
disp(q);
r = str2num(fgetl(fid));
disp(' R');
disp('====================');
disp(r);
x=A*p'
y=B*x'
z=y+q
s=z'*r'



Microsoft Excel
s=(ABp+q,r)
.

1 2 3
A = 1 2 1

3 2 0

4 1 2
B = 0 4 3

1 1 1

.
01
p = 1.7

15
.

.
16
q = 0.8

11
.

0.7
r = 13
.

0.2

x=Bp

x=Bp

CTRL + SHIFT + ENTER

x E5:E7

y=Ax

z=y+q

s=(z,r)





- ( )

SCREEN SHOT
( )

-1-1

: .

Вам также может понравиться