Sie sind auf Seite 1von 40

%-- 25/02/14 19:45 --%

%-- 25/02/14 20:14 --%


%-- 25/02/14 20:17 --%
%-- 26/02/14 6:52 --%
2+3
2/3
a=2
a=2,a*2
a =2
a*2
a
a=a*2
a
x=[1479]
y=[5678]
sum (x)
sum (x .* y )
sum (x * y )
size (x)
n = ( sum (x) * sum (y) - 4 * sum (x .*y)) / ( sum (x)^2 - 4 * sum (x .^2))
5*x
x*5
6+x
sum (x.^2)
sum ((x-2).^2)
x
x (1,[1 3])

x (1,[1 2 3])
x (1,[1;3])
x (1,[1:3])
A = [1 5 5; 4 6 24; 7 7 49; 9 8 72]
A (:, [1 2])
A [2, :]
A (2, :)
A ([2 4], :)
B = A.^2
C = [A A.^2 A.^3]
C = [A' A'.^2 A'.^3]
C = [A (: , 1) A (: , 2).^2 A (:,3).^3
C = [A (: , 1) A (: , 2).^2 A (:,3).^3]
C = [A (: , 1) A (: , 2).^2 A (: , 3).^3]
C = [A(:,1) A(:,2).^2 A(:,3).^3]
sum (A(: [1 2]))
sum (A(:,[1 2]))
sum(sum (A(:,[1 2])))
sum (A([1 3 4],:))
sum(sum (A([1 3 4],:)))
sum(1 : 100)
sum(1:2:100)
((1:100).^2)
((1:10).^2)
sum((1:10).^2)
sum((1:10)./2)
1./(1:10)

sum(1./(1:10))
2./(1:10)
sum(2./(1:10))
(1:10./(1+(1:10).^2)
(1:10)./(1+(1:10).^2)
sum((1:10)./(1+(1:10).^2))
1+sum(2:2:10)- sum(3:2:9)
(-1).^(2:10)
(-1).^(2:10).*(2:10)
1+ sum(-1).^(2:10).*(2:10)
%-- 01/03/14 17:28 --%
%-- 04/03/14 19:44 --%

>> (2:10)./(3+(1:9).^2)

ans =

0.5000 0.4286 0.3333 0.2632 0.2143 0.1795 0.1538 0.1343 0.1190

>> (-1).^(2:10).*(2:10)./(3+(1:9).^2)

ans =

0.5000 -0.4286 0.3333 -0.2632 0.2143 -0.1795 0.1538 -0.1343 0.1190

Pertemuan ke 3
>> (2:10)./(3+(1:9).^2)

ans =

0.5000 0.4286 0.3333 0.2632 0.2143 0.1795 0.1538 0.1343 0.1190

>> (-1).^(2:10).*(2:10)./(3+(1:9).^2)

ans =

0.5000 -0.4286 0.3333 -0.2632 0.2143 -0.1795 0.1538 -0.1343 0.1190

>> format long

>> 1/3

ans =

0.333333333333333

>> format rasiomal


??? Error using ==> format
Unknown command option.

>> format rasional

??? Error using ==> format


Unknown command option.

>> format rational


>> 1/3:1/2

ans =

1/3

>> 0,3777777777

ans =

ans =

3777777777

>> 0.37777777777777

ans =

17/45

>> 0.37777777777777777777777777777777

ans =

17/45

>> format short


>> 2/0

ans =

Inf

>> log(0)

ans =

-Inf

>> 00

ans =

>> 0/0

ans =

NaN

>> A=[1 2 3]

A=

>> B=[2 3 4]

B=

>> A+B

ans =

>> B-A

ans =

>> A'+B
??? Error using ==> plus
Matrix dimensions must agree.

>> A'

ans =

1
2
3

>> B

B=

>> 1<2

ans =

>> A=2>=4

A=

>> A=B>3

A=

>> B

B=

>> once (2,3)


??? Undefined function or method 'once' for input arguments of type 'double'.

>> once(2,3)
??? Undefined function or method 'once' for input arguments of type 'double'.

>> ones (2,3)

ans =

>> pi

ans =

3.1416

>> eps

ans =

2.2204e-016

>> namelengthmax

ans =

63

>> y=@(x) 1 + 2./(x.^3+4)

y=

@(x)1+2./(x.^3+4)

>> y([1 2])

ans =

1.4000 1.1667

>> x=0

x=

>> x=0:0.5:3;
>> y(x)

ans =

1.5000 1.4848 1.4000 1.2712 1.1667 1.1019 1.0645

>> [x' y(x)]


??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

>> x=x=0:0.5:3
??? x=x=0:0.5:3
|
Error: The expression to the left of the equals sign is not a valid target for an assignment.

>> x=0:0.5:3

x=

0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000

>> x=0:0.5:3;
>> y(x)

ans =

1.5000 1.4848 1.4000 1.2712 1.1667 1.1019 1.0645

>> [x' y(x)]


??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

>> [x' y(x')]

ans =

0 1.5000
0.5000 1.4848
1.0000 1.4000
1.5000 1.2712
2.0000 1.1667
2.5000 1.1019

3.0000 1.0645

>> d=[1:10]

d=

9 10

>> luas=0.25*pi.*.^2
??? luas=0.25*pi.*.^2
|
Error: Unexpected MATLAB operator.

>> luas=0.25*pi.*d.^2

luas =

0.7854 3.1416 7.0686 12.5664 19.6350 28.2743 38.4845 50.2655 63.6173 78.5398

>> [d' luas']

ans =

1.0000 0.7854
2.0000 3.1416
3.0000 7.0686
4.0000 12.5664

5.0000 19.6350
6.0000 28.2743
7.0000 38.4845
8.0000 50.2655
9.0000 63.6173
10.0000 78.5398

>> luas=@(d).pi/4*d.^2
??? luas=@(d).pi/4*d.^2
|
Error: Unexpected MATLAB operator.

>> L=@(d).pi/4*d.^2
??? L=@(d).pi/4*d.^2
|
Error: Unexpected MATLAB operator.

>> L=@(d) pi/4*d.^2

L=

@(d)pi/4*d.^2

>> [d' (L(d')]


??? [d' (L(d')]
|
Error: Unbalanced or unexpected parenthesis or bracket.

>> [d' L(d')]

ans =

1.0000 0.7854
2.0000 3.1416
3.0000 7.0686
4.0000 12.5664
5.0000 19.6350
6.0000 28.2743
7.0000 38.4845
8.0000 50.2655
9.0000 63.6173
10.0000 78.5398

>> @(X)x.*4500

ans =

@(X)x.*4500

Pertemuan ke 4
>> p=[ 1 -3 -13 15 ]

p=

1 -3 -13 15

>> roots (p)

ans =

5.0000
-3.0000
1.0000

>> polyval (p,2)

ans =

-15

>> y=@(x) polyval (p,x)

y=

@(x)polyval(p,x)

>> y=@(x) polyval (p,x)-2

y=

@(x)polyval(p,x)-2

>> fzero (y,1)

ans =

0.8749

>> p1= [ 1 -3 -13 13 ]

p1 =

1 -3 -13 13

>> roots (p1)

ans =

5.0611
-2.9360
0.8749

>> fzero (y,4)

ans =

5.0611

>> fzero (y,-1)

ans =

0.8749

>> fzero (y,-3)

ans =

-2.9360

>> xdata=[-5:0.1:5];
>> plot (xdata,polyval(p1,xdata));grid on
>> conv =([1 -1],[1 1 1])
??? conv =([1 -1],[1 1 1])
|
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

>> conv([1 -1],[1 1 1])

ans =

0 -1

>> deconv ([1 0 0 -1],[1 -1])

ans =

>> a=[2 3 -32 15]; b=[1 2 -15]; [r p k]= residue(a,b)

r=

0
0

p=

-5
3

k=

2 -1

>> x=[1 2 3 7 8 10]; y=[9 11 11.3 12.5 13.1 22]; p3=polyfit(x,y,3)

p3 =

0.0726 -0.9925 4.2963 5.6345

>> p2=polyfit(x,y,2)

p2 =

0.2527 -1.6744 12.2419

>> p4=polyfit(x,y,4)

p4 =

0.0081 -0.0996 0.1841 1.4937 7.5414

>> p5=polyfit(x,y,5)

p5 =

0.0044 -0.1108 1.0736 -4.9167 10.7606 2.1889

>> plot(x,y,'o')
>> xdata=1-:0.1:15;
??? xdata=1-:0.1:15;

|
Error: Unexpected MATLAB operator.

>> xdata=-1:0.1:15;
>> plot(x,y,'o',xdata,polyval(p5,xdata))
>> plot(x,y,'o',xdata,polyval(p5,xdata),xdata,polyval(p5,xdata))
>> plot(x,y,'o',xdata,polyval(p5,xdata),xdata,polyval(p4,xdata))
>> plot(x,y,'o',xdata,polyval(p5,xdata),xdata,polyval(p4,xdata),xdata,polyval(p3,xdata))
>>
plot(x,y,'o',xdata,polyval(p5,xdata),xdata,polyval(p4,xdata),xdata,polyval(p3,xdata),xdata,polyval(p2,
xdata))
>> p2

p2 =

0.2527 -1.6744 12.2419

>> y

y=

9.0000 11.0000 11.3000 12.5000 13.1000 22.0000

>> x

x=

8 10

>> polyval(p2,1)

ans =

10.8202

>> polyval(p2,2)

ans =

9.9038

>> polyval(p2,x)

ans =

10.8202 9.9038 9.4927 12.9017 15.0173 20.7644

>> y2=polyval(p2,x)

y2 =

10.8202 9.9038 9.4927 12.9017 15.0173 20.7644

>> y-y2

ans =

-1.8202 1.0962 1.8073 -0.4017 -1.9173 1.2356

>> (y-y2).^2

ans =

3.3130 1.2017 3.2664 0.1614 3.6759 1.5267

>> SSE2=sum((y-y2).^2)

SSE2 =

13.1451

>> y3=polyval(p3,x)

y3 =

9.0108 10.8374 11.5496 11.9628 13.6340 21.9054

>> SSE2=sum((y-y3).^2)

SSE2 =

0.6715

>> y4=polyval(p4,x)

y4 =

9.1277 10.5978 11.6447 12.2319 13.3298 21.9681

>> SSE4=sum((y-y4).^2)

SSE4 =

0.4226

>> y5=polyval(p5,x)

y5 =

9.0000 11.0000 11.3000 12.5000 13.1000 22.0000

>> SSE5=sum((y-y5).^2)

SSE5 =

4.1522e-026

>> polyval (p5,2.5)

ans =

11.2370

>> polyval (p2,2.5)

ans =

9.6351

>> [x' y']

ans =

1.0000 9.0000
2.0000 11.0000
3.0000 11.3000
7.0000 12.5000
8.0000 13.1000
10.0000 22.0000

>> polyval(p5,9)

ans =

15.3022

>> interp1 (x,y,9)

ans =

17.5500

>> interp1 (x,y,9,'spline')

ans =

15.6017

>> interp1 (x,y,9,'cubic')

ans =

16.0395

>> p

p=

-5
3

>> p5

p5 =

0.0044 -0.1108 1.0736 -4.9167 10.7606 2.1889

>> p=p5

p=

0.0044 -0.1108 1.0736 -4.9167 10.7606 2.1889

>> p(6)=p(6)-15

p=

0.0044 -0.1108 1.0736 -4.9167 10.7606 -12.8111

>> roots (p)

ans =

8.9169
6.7343 + 2.9170i
6.7343 - 2.9170i
1.4553 + 1.9937i
1.4553 - 1.9937i

>> polyval (p5,8.9169)

ans =

15.0000

>>
>> interp1 (y,x,15)

ans =

8.4270

>> interp1 (y,x,15,'spline')

ans =

6.4845

>> interp1 (y,x,15,'cubic')

ans =

8.8329

>> a=@(x) polyval (p5,x)

a=

@(x)polyval(p5,x)

>> a=@(x) polyval (p5,x)-15

a=

@(x)polyval(p5,x)-15

>> fzero(a,5)

ans =

8.9169

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


>> y=[ 0 14 44 96 176];
>> y=[ 0 14 44 96 176];
>> pa1=polyfit (x,y,4)

pa1 =

0.0000 1.0000 2.0000 1.0000 -4.0000

>> xdata=[1.5 2.5 3.5 4.5]

xdata =

1.5000 2.5000 3.5000 4.5000

>> polyval(pal,xdata)
??? Undefined function or variable 'pal'.

>> polyval(pa1,xdata)

ans =

5.3750 26.6250 66.8750 132.1250

Pertemuan ke 5
>> x=[0:5]',

x=

0
1
2
3
4
5

>> y=[ 1 2 5 10 17 26]',

y=

1
2
5
10
17
26

>> m1=[x.^2 x ones(size(x))]

m1 =

16

25

>> abc=m1\y

abc =

1.0000
-0.0000
1.0000

>> a=abc(1)

a=

1.0000

>> b=abc(2)

b=

-2.4487e-015

>> c=abc(3)

c=

1.0000

>> m2=[x.^2 ones(size(x))]

m2 =

16

25

>> ab=m2\y

ab =

1.0000
1.0000

>> a=ab(1)

a=

>> b=ab(2)

b=

1.0000

>> m3=[ones(size(x)) x.^2]

m3 =

1 16
1 25

>> ab=m3\y

ab =

1.0000
1.0000

>> a=ab(1)

a=

1.0000

>> b=ab(2)

b=

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


>> y=[6 20 58 132 254]';
>> x=

??? x=
|
Error: Expression or statement is incomplete or incorrect.

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

x=

1
2
3
4
5

>> y=[6 20 58 132 254]'

y=

6
20
58
132
254

>> m=[ones(size(x)) log(x)]

m=

1.0000

1.0000 0.6931
1.0000 1.0986
1.0000 1.3863
1.0000 1.6094

>> ab=m\log(y)

ab =

1.6196
2.3332

>> a=exp(ab(1))

a=

5.0512

>> b=ab(2)

b=

2.3332

>> y=@(x) x.^3-x-1; x0=fzero(y,4)

x0 =

1.3247

>> y=@(x) x.^3-x-1; x0=fzero(y,3)

x0 =

1.3247

>> A=[1 2 3]

A=

>> xdata=[-10:0.1:10];
>> plot=(xdata,y(xdata))
??? plot=(xdata,y(xdata))
|
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

>> plot(xdata,y(xdata))
>> plot(xdata,y(xdata));grid on
>> xdata=[-2:0.1:2];
>> plot(xdata,y(xdata))

>> plot(xdata,y(xdata));grid on
>> y=@(x) 73*(2*x-3).*(x-5); a=fzero(y,1), b= fzero(y,6)
??? y=@(x) 73*(2*x-3).*(x-5); a=fzero(y,1), b= fzero(y,6)
|
Error: The input character is not valid in MATLAB statements or expressions.

>> y=@(x) 7-3*(2*x-3).*(x-5); a=fzero(y,1), b= fzero(y,6)

a=

1.1935

b=

5.3065

>> fzero (y,20)

ans =

5.3065

>> fzero (y,10)

ans =

5.3065

>> fzero (y,-10)

ans =

1.1935

>>

Das könnte Ihnen auch gefallen