You are on page 1of 10

1)

for f=1:7
for c=1:7
if ( f+c==2|f+c==3|f+c==4|f+c==5|f+c==6|f+c==7)
B(f,c)=0;
elseif f+c==8
B(f,c)=1;
elseif f+c==9
B(f,c)=2;
elseif f+c==10
B(f,c)=3;
elseif f+c==11
B(f,c)=4;
elseif f+c==12
B(f,c)=5;
elseif f+c==13
B(f,c)=6;
else
B(f,c)=7;
end
end
end
display(B)

B=

0 0 0 0 0 0 1

0 0 0 0 0 1 2

0 0 0 0 1 2 3

0 0 0 1 2 3 4

0 0 1 2 3 4 5

0 1 2 3 4 5 6

1 2 3 4 5 6 7

2)
for f=1:6
for c=1:6
if c==1
B(f,c)=32;
elseif c==2
B(f,c)=16;
elseif c==3
B(f,c)=8;
elseif c==4
B(f,c)=4;
elseif c==5
B(f,c)=2;
else
B(f,c)=1;
end
end
end
display(B)

B=

32 16 8 4 2 1

32 16 8 4 2 1

32 16 8 4 2 1

32 16 8 4 2 1

32 16 8 4 2 1

32 16 8 4 2 1

>>

3)
x=-3:0.05:3
y1=3.*x.^2;
y2=exp(x);
plot(x,y1,'r',x,y2,'b')
grid on

30

25

20

15

10

0
-3 -2 -1 0 1 2 3
>> a=-1,b=0,tol=5*10^-9

a=

-1

b=

tol =

5.000000000000000e-009

>> [c]=bisec('f11',a,b,tol)

0 -1.0000000 0.0000000 -0.5000000 0.1434693

1 -0.5000000 0.0000000 -0.2500000 -0.5913008

2 -0.5000000 -0.2500000 -0.3750000 -0.2654143

3 -0.5000000 -0.3750000 -0.4375000 -0.0714298

4 -0.5000000 -0.4375000 -0.4687500 0.0333957

5 -0.4687500 -0.4375000 -0.4531250 -0.0196719

6 -0.4687500 -0.4531250 -0.4609375 0.0066980

7 -0.4609375 -0.4531250 -0.4570313 -0.0065279

8 -0.4609375 -0.4570313 -0.4589844 0.0000749

9 -0.4589844 -0.4570313 -0.4580078 -0.0032291

10 -0.4589844 -0.4580078 -0.4584961 -0.0015777

11 -0.4589844 -0.4584961 -0.4587402 -0.0007516

12 -0.4589844 -0.4587402 -0.4588623 -0.0003384


13 -0.4589844 -0.4588623 -0.4589233 -0.0001318

14 -0.4589844 -0.4589233 -0.4589539 -0.0000285

15 -0.4589844 -0.4589539 -0.4589691 0.0000232

16 -0.4589691 -0.4589539 -0.4589615 -0.0000026

17 -0.4589691 -0.4589615 -0.4589653 0.0000103

18 -0.4589653 -0.4589615 -0.4589634 0.0000038

19 -0.4589634 -0.4589615 -0.4589624 0.0000006

20 -0.4589624 -0.4589615 -0.4589620 -0.0000010

21 -0.4589624 -0.4589620 -0.4589622 -0.0000002

22 -0.4589624 -0.4589622 -0.4589623 0.0000002

23 -0.4589623 -0.4589622 -0.4589623 -0.0000000

24 -0.4589623 -0.4589623 -0.4589623 0.0000001

25 -0.4589623 -0.4589623 -0.4589623 0.0000000

26 -0.4589623 -0.4589623 -0.4589623 0.0000000

c=

-0.458962269127369

>>

4
a)

clc
clear
k=1
while (1+(k+1))/(k*(k+1))> (5*(10^ -3))
U(k)=(2*k+2)/(2*k*(2*k+1));
k=k+1;
end
display(U)

k =

U =

Columns 1 through 6
0.666666666666667 0.300000000000000 0.190476190476190
0.138888888888889 0.109090909090909 0.089743589743590

Columns 7 through 12

0.076190476190476 0.066176470588235 0.058479532163743


0.052380952380952 0.047430830039526 0.043333333333333

Columns 13 through 18

0.039886039886040 0.036945812807882 0.034408602150538


0.032196969696970 0.030252100840336 0.028528528528529

Columns 19 through 24

0.026990553306343 0.025609756097561 0.024363233665559


0.023232323232323 0.022201665124884 0.021258503401361

Columns 25 through 30

0.020392156862745 0.019593613933237 0.018855218855219


0.018170426065163 0.017533606078317 0.016939890710383

Columns 31 through 36

0.016385048643113 0.015865384615385 0.015377657168702


0.014919011082694 0.014486921529175 0.014079147640791

Columns 37 through 42

0.013693693693694 0.013328776486671 0.012982797792924


0.012654320987654 0.012342051131355 0.012044817927171

Columns 43 through 48

0.011761561079925 0.011491317671093 0.011233211233211


0.010986442262740 0.010750279955207 0.010524054982818

Columns 49 through 54

0.010307153164296 0.010099009900990 0.009899105273177


0.009706959706960 0.009522130135779 0.009344206591913

Columns 55 through 60

0.009172809172809 0.009007585335019 0.008848207475210


0.008694370763336 0.008545791197835 0.008402203856749

Columns 61 through 66

0.008263361322138 0.008129032258065 0.007999000124984


0.007873062015504 0.007751027598356 0.007632718159034

Columns 67 through 72

0.007517965726921 0.007406612279948 0.007298509018872


0.007193515704154 0.007091500049247 0.006992337164751

Columns 73 through 78
0.006895909048551 0.006802104117540 0.006710816777042
0.006621947024424 0.006535400083787 0.006451086068920

Columns 79 through 84

0.006368919672001 0.006288819875776 0.006210709687192


0.006134515890613 0.006060168818989 0.005987602141448

Columns 85 through 90

0.005916752665979 0.005847560155935 0.005779967159278


0.005713918849512 0.005649362877409 0.005586249232658

Columns 91 through 96

0.005524530114694 0.005464159811986 0.005405094589155


0.005347292581335 0.005290713695233 0.005235319516408

Columns 97 through 102

0.005181073222310 0.005127939500673 0.005075884472869


0.005024875621891 0.004974881724626 0.004925872788140

Columns 103 through 108

0.004877819989682 0.004830695620169 0.004784473030919


0.004739126583400 0.004694631601826 0.004650964328384

Columns 109 through 114

0.004608101880943 0.004566022213081 0.004524704076274


0.004484126984127 0.004444271178512 0.004405117597487

Columns 115 through 120

0.004366647844909 0.004328844161610 0.004291689398072


0.004255166988486 0.004219260926128 0.004183955739972

Columns 121 through 126

0.004149236472469 0.004115088658414 0.004081498304862


0.004048451872004 0.004015936254980 0.003983938766547

Columns 127 through 132

0.003952447120581 0.003921449416342 0.003890934123492


0.003860890067787 0.003831306417438 0.003802172670097

Columns 133 through 138

0.003773478640421 0.003745214448205 0.003717370507038


0.003689937513467 0.003662906436629 0.003636268508345

Columns 139 through 144

0.003610015213636 0.003584138281647 0.003558629676967


0.003533481591302 0.003508686435516 0.003484236831988

Columns 145 through 150


0.003460125607299 0.003436345785217 0.003412890579961
0.003389753389753 0.003366927790622 0.003344407530454

Columns 151 through 156

0.003322186523288 0.003300258843831 0.003278618722190


0.003257260538814 0.003236178819625 0.003215368231343

Columns 157 through 162

0.003194823576989 0.003174539791559 0.003154511937856


0.003134735202492 0.003115204892025 0.003095916429250

Columns 163 through 168

0.003076865349618 0.003058047297798 0.003039458024352


0.003021093382539 0.003002949325230 0.002985021901936

Columns 169 through 174

0.002967307255939 0.002949801621528 0.002932501321331


0.002915402763734 0.002898502440406 0.002881796923888

Columns 175 through 180

0.002865282865283 0.002848956992016 0.002832816105674


0.002816857079911 0.002801076858437 0.002785472453062

Columns 181 through 186

0.002770040941814 0.002754779467108 0.002739685233990


0.002724755508425 0.002709987615648 0.002695378938568

Columns 187 through 192

0.002680926916221 0.002666629042271 0.002652482863565


0.002638485978726 0.002624636036800 0.002610930735931

Columns 193 through 198

0.002597367822094 0.002583945087854 0.002570660371172


0.002557511554240 0.002544496562359 0.002531613362848

Columns 199 through 200

0.002518859963980 0.002506234413965

>>

b)

clc
clear
k=1
while (2*k+2)/(2*k*(2*k+1))> 5*10^ -3
U(k)=(2*k+2)/(2*k*(2*k+1));
k=k+1;
end
display(U)

k =
1

U =

Columns 1 through 6

0.666666666666667 0.300000000000000
0.190476190476190 0.138888888888889 0.109090909090909
0.089743589743590

Columns 7 through 12

0.076190476190476 0.066176470588235
0.058479532163743 0.052380952380952 0.047430830039526
0.043333333333333

Columns 13 through 18

0.039886039886040 0.036945812807882
0.034408602150538 0.032196969696970 0.030252100840336
0.028528528528529

Columns 19 through 24

0.026990553306343 0.025609756097561
0.024363233665559 0.023232323232323 0.022201665124884
0.021258503401361

Columns 25 through 30

0.020392156862745 0.019593613933237
0.018855218855219 0.018170426065163 0.017533606078317
0.016939890710383

Columns 31 through 36

0.016385048643113 0.015865384615385
0.015377657168702 0.014919011082694 0.014486921529175
0.014079147640791

Columns 37 through 42

0.013693693693694 0.013328776486671
0.012982797792924 0.012654320987654 0.012342051131355
0.012044817927171

Columns 43 through 48
0.011761561079925 0.011491317671093
0.011233211233211 0.010986442262740 0.010750279955207
0.010524054982818

Columns 49 through 54

0.010307153164296 0.010099009900990
0.009899105273177 0.009706959706960 0.009522130135779
0.009344206591913

Columns 55 through 60

0.009172809172809 0.009007585335019
0.008848207475210 0.008694370763336 0.008545791197835
0.008402203856749

Columns 61 through 66

0.008263361322138 0.008129032258065
0.007999000124984 0.007873062015504 0.007751027598356
0.007632718159034

Columns 67 through 72

0.007517965726921 0.007406612279948
0.007298509018872 0.007193515704154 0.007091500049247
0.006992337164751

Columns 73 through 78

0.006895909048551 0.006802104117540
0.006710816777042 0.006621947024424 0.006535400083787
0.006451086068920

Columns 79 through 84

0.006368919672001 0.006288819875776
0.006210709687192 0.006134515890613 0.006060168818989
0.005987602141448

Columns 85 through 90

0.005916752665979 0.005847560155935
0.005779967159278 0.005713918849512 0.005649362877409
0.005586249232658

Columns 91 through 96

0.005524530114694 0.005464159811986
0.005405094589155 0.005347292581335 0.005290713695233
0.005235319516408
Columns 97 through 100

0.005181073222310 0.005127939500673
0.005075884472869 0.005024875621891

>>

You might also like