loops - לולאות

44
3.1/40 רררררר רר ררררר: רררר ררררררר. ררררר רFor ררררר רWhile ררררר ררררררר ר"רBreak ררררר. רררר רררררר רררררMatLab (22100) רררר רררררר – ררררר רררררר

Upload: michael

Post on 15-Nov-2014

139 views

Category:

Documents


1 download

DESCRIPTION

מצגות מקורס מבוא לתכנות בעזרת MATLAB במכללת אורט בראודה

TRANSCRIPT

04/1.3

: . For While " Break .

MatLab 00122))

04/2.3

. For While " Break .

MatLab 00122))

04/3.3

( ). : : , , .. , ... , , . MATLAB %01 . . MatLab 00122))

04/4.3

: ( ) . : . 01 , 01 , '. : for " ' . while ' MatLab 00122))

04/5.3

. For While " Break .

MatLab 00122))

04/6.3

FORfor 01:1=jdone

: 01:1=for j ;% computations end : 01:2:1=for j ;% computations end

computations

' ( 01). . . " BREAK MatLab 00122))

04/7.3

' 1: : . 01 . . . . , -02 . . 02.

MatLab 00122))

04/8.3

: Smalls 02 N

S P

MatLab 00122))

3.9/40

: 1 - % calculate the area and circumference of 10 circles . %print out if the area is greater than 20 and counts the others

Smalls = 0; for N = 1:10 fprintf(\nplease enter radius number %d ', N); R = input( '); S = pi * R^2; P = 2 * pi * R; if S > 20 fprintf('\n Radius = %f units', R); fprintf('\n Area = %f units squared', S); fprintf('\n Circumference = %f units', P); else Smalls = Smalls + 1; end %end if end %end for fprintf('\n the number of circles with area less or equal 20 is: %d ,Smalls);

MatLab ))22100

3.10/40

please enter radius number 1 10 Radius = 10.00 units Area = 314.16 units squared Circumference = 62.83 units please enter radius number 2 please enter radius number 3 Radius = 12.00 units Area = 452.39 units squared Circumference = 75.40 units please enter radius number 4 please enter radius number 5 1 12

FOR :

0.5 0.7

please enter radius number 6 90 Radius = 90.00 units Area = 25446.90 units squared Circumference = 565.49 units please enter radius number 7 Radius = 13.00 units Area = 530.93 units squared Circumference = 81.68 units please enter radius number 8 please enter radius number 9 Radius = 5.00 units Area = 78.54 units squared Circumference = 31.42 units 13

0.1 5

please enter radius number 10 0.01 the number of circles with area less or equal 20 is: 5 >>

04/11.3

1.1 1, 02

00122) ) MatLab

3.12/40

1.1 -

Smalls = []; for N = 1:10 fprintf)'\n please enter radius number %d ', N(; R = input)' '(; S = pi * R^2; P = 2 * pi * R; if S > 20 fprintf)'\n Radius = %.2f units', R(; fprintf)'\n Area = %.2f units squared', S(; fprintf)'\n Circumference = %.2f units', P(; else Smalls = [Smalls,R]; end %end if end %end for fprintf)'\n the number of circles with area less or equal 20 is: %d ',length)Smalls((;'

04/31.3

2

51 , 0 1.

00122) ) MatLab

04/41.3

2 -

51:1=for I 0==(2,if rem)I ;0=(V)I else ;1=(V)I end end ;(disp)V

:

00122) ) MatLab

04/51.3

. For While " Break .

MatLab 00122))

04/61.3

While : ;0=k 0155 | ptor ;% computations end

next

WHILE . ( k) , ( grade ptor). MatLab 00122))

04/71.3

' 3: : . . . . . , -02 . . 02. . .

MatLab 00122))

04/81.3

3 - :

-

WHILE loop

MatLab 00122))

3.19/40% calculate the area and circumference of unknown circles . %print out if the area is greater than 20 and counts the others % the program terminates if radius < = 0 Smalls=0; R=input(please enter first radius:); While R > 0 S= pi * R^2; P = 2 * pi * R; if S> 20 fprintf('\n Radius = %f units', R); fprintf('\n Area = %f units squared', S); fprintf('\n Circumference = %f units', P); else Smalls = Smalls + 1; end %end if R= input(please enter the next radius: end %end while fprintf('\nthe number of circles with area less or equal 20 is: %d, Smalls); ');

: 3 -

MatLab ))22100

3.20/40

please enter first radius:10 Radius = 10.00 units Area = 314.16 units squared Circumference = 62.83 units please enter the next radius: 1 please enter the next radius: 15 Radius = 15.00 units Area = 706.86 units squared Circumference = 94.25 units please enter the next radius: 0.3 please enter the next radius: 0

:

the number of circles with area less or equal 20 is: 2>>

MatLab ))22100

04/12.3

4

00122) ) MatLab

04/22.3

4

:

00122) ) MatLab

3.23/40

4.0 10- a=input)'Enter a new vector:'(; i=1; while i