Chöông 2 : Laäp Trình M-file

40

description

Chöông 2 : Laäp Trình M-file. Chöông goàm caùc ñeà muïc : Laäp trình vôùi m file. Toùan töû so saùnh vaø toùan töû logic . Caáu truùc ñieàu khieån. Xöû lyù chuoåi (string). Maûng caáu truùc. Maûng cell. 1) Laäp Trình m file : Ñieåm maïnh cuûa matlab laø ngoân ngöõ laäp trình. - PowerPoint PPT Presentation

Transcript of Chöông 2 : Laäp Trình M-file

Page 1: Chöông 2 : Laäp Trình M-file
Page 2: Chöông 2 : Laäp Trình M-file

Chöông 2 : Laäp Trình M-file

Chöông goàm caùc ñeà muïc : Laäp trình vôùi m file. Toùan töû so saùnh vaø toùan töû logic. Caáu truùc ñieàu khieån. Xöû lyù chuoåi (string). Maûng caáu truùc. Maûng cell.

Page 3: Chöông 2 : Laäp Trình M-file

1) Laäp Trình m file : Ñieåm maïnh cuûa matlab laø ngoân ngöõ laäp

trình. File chöùa maõ nguoàn ngoân ngöõ laäp trình Matlab laø

m-file. Phaàn ñuoâi cuûa m-file laø .m. Taïo moät m-file chöùa maõ nguoàn, choïn leänh New-

file vaø choïn m-file. Coù hai loïai m-file : script m-file vaø function m-file.

Script m-file : khoâng coù ñoái soá vaøo, vaän haønh trong vuøng workspace, chöùa caùc leänh vaø haøm cuûa matlab.

Function m-file : coù caùc ñoái soá vaøo ra. Cuù phaùp taïo haøm m-file laøfunction [arg1, . . ,argN] = <fun_name>( input_args )

<body of function>;

% end of function

Page 4: Chöông 2 : Laäp Trình M-file

Ví duï : Chöông trình sau laø moät ví duï minh chöùng cuûa moät script m-file.% Chöông trình veõ moät ñöôøng troøn coù taâm laø (3,2) vaø baùn kính laø 3.

t = 0:pi/100:2*pi;x = 3 + 3*cos(t);y = 2 + 3*sin(t);plot(x,y), axis(‘square’),grid

% End of program Chöông trình sau laø moät ví duï minh chöùng

cuûa moät haøm m-file.% Giaûi phöông trình baäc hai

function [x1,x2] = quadroot(a,b,c)x = roots([a b c]);x1 = x(1);x2 = x(2);

% End of function

Page 5: Chöông 2 : Laäp Trình M-file

2) Toùan Töû So Saùnh vaø Toùan Töû Logic :

Toùan töû so saùnh : < : nhoû hôn. <= : nhoû hôn hoaëc baèng. > : lôùn hôn. >= : lôùn hôn hoaëc baèng. == : baèng nhau. ~= : khoâng baèng nhau.

Toùan töû logic : & : toùan töû vaø. | : toùan töû hoaëc. ~ : toùan töû phuû ñònh.

3) Caáu Truùc Ñieàu Khieån : Leänh if, else vaø elseif :

Page 6: Chöông 2 : Laäp Trình M-file

Leänh if : cuù phaùp laøif <logical expression>

body of if statement;end

Ví duï : Chöông trình sau laø moät ví duï minh chöùng söû duïng leänh if.

%Begining of programstr = input('Ve do thi sin(x)[y/n]','s');if str == 'y' x = 0:pi/100:2*pi; y = sin(x); plot(x,y),grid xlabel('X'),ylabel('Y') title('Sin(x)')end % End of program

Page 7: Chöông 2 : Laäp Trình M-file

Leänh if-else : cuù phaùp laøif <logical expression>

body of if statement;else

body of else statement;end

Ví duï : Chöông trình sau laø moät ví duï minh chöùng söû duïng leänh if-else.

%Begining of programnum = input('Enter any number :');if num >= 0.0 disp('Positive number');else display('Negative number');end%End of program

Page 8: Chöông 2 : Laäp Trình M-file

Leänh if-elseif-else : cuù phaùp laøif <logical expression1>

body of if statement;elseif <logical expression2>

body of elseif statement;else

body of else statement;end

Ví duï : Chöông trình sau laø moät ví duï minh chöùng söû duïng leänh if-elseif-else.

%Begining of programnum = input('Enter any number :');if num > 0.0 disp('Positive number');elseif num == 0.0 display('Zero number');else disp('Negative number')end%End of program

Page 9: Chöông 2 : Laäp Trình M-file

Leänh switch : leänh choïn löïa moät trong caùc tröôøng hôïp ñeå thöïc hieän vôùi cuù phaùp laø

switch <expression>case value1

statements;case valu2

statements;

case valueNstatements;

otherwisestatements;

end

Page 10: Chöông 2 : Laäp Trình M-file

Ví duï : Chöông trình sau laø moät ví duï minh chöùng söû duïng leänh switch.

%Begining of programnum = input('Enter number :');switch num case -1 disp('Negative one'); case 0 disp('Zero'); case 1 disp('Positive one'); otherwise disp('Other number')end%End of program

Page 11: Chöông 2 : Laäp Trình M-file

Leänh while : thöïc hieän voøng laëp khi bieåu thöùc logic true vôùi cuù phaùp laø

while <logical exprerssion>body of while statements;

endVí duï : Chöông trình sau laø moät ví duï

minh chöùng söû duïng leänh while.%Begining of programnum = input('Enter integer number :');fact = 1;while num > 1 fact = fact*num; num = num - 1;endfact%End of program

Page 12: Chöông 2 : Laäp Trình M-file

Leänh for : thöïc hieän voøng laëp vôùi soá laàn ñöôïc xaùc ñònh.

for index = start:increment:endbody of for statements;

endVí duï : Chöông trình sau laø moät ví duï minh

chöùng söû duïng leänh for.%Begining of programrow = input('Enter number of rows :');colum = input('Enter number of colums :');for i = 1:row for j = 1:colum c(i,j) = 1/(i + j - 1); endendc%End of program

Page 13: Chöông 2 : Laäp Trình M-file

Leänh break : keát thuùc voøng laëp coù ñieàu kieän.

Ví duï : chöông trình sau laø moät ví duï minh chöùng.

%Begining of programclearnum = input('Enter integer number :');fact = 1;while num > 1 if num < 0 break; else fact = fact*num; num = num - 1; endendfact%End of program

Page 14: Chöông 2 : Laäp Trình M-file

Leänh continue : boû qua moät coâng ñoïan trong voøng laëp ñeå tieáp tuïc thöïc hieän voøng laëp môùi.

Ví duï : Chöông trình sau laø moät ví duï minh chöùng.

%Begining of programcleara = zeros(6);for i = 1:6 for j = 1:6 if i == j continue; else a(i,j) = i*j; end endenda%End of program

Page 15: Chöông 2 : Laäp Trình M-file

Leänh return : Leänh thöôøng ñöôïc söû duïng trong haøm m-file boû qua phaàn coâng ñoïan cuûa haøm hoaë traû veà keát thuùc maõ baøn phím.

Ví duï : Chöông trình sau laø moät ví duï minh chöùng söû duïng leänh return.

function d = deter(A)if isempty(A) d = 1; returnelse d = det(A);end

Haøm con (sub function) : m-file coù theå chöùa nhieàu haøm, haøm ñaàu tieân laø haøm chính phaûi coù cuøng teân vôùi m-file, caùc haøm coøn laïi laø caùc haøm con phaûi coù khaùc teân vôùi m-file.

Page 16: Chöông 2 : Laäp Trình M-file

Ví duï : Chöông trình sau laø moät ví duï minh chöùng.function [z,s] = main(x,y)z = total(x,y);s = subtract(x,y);function z = total(x,y)z = x + y;function s = subtract(x,y)s = x – y;%end of function

Haøm private : haøm private laø haøm thöôøng truù trong thö muïc

ñaëc bieät private. Haøm cho pheùp ñöôïc söû duïng vôùi caùc haøm m-

file khaùc thöôøng truù trong thö muïc cha. Haøm private phaûi coù cuøng teân vôùi thö muïc

private.

Page 17: Chöông 2 : Laäp Trình M-file

4) Xöû Lyù Chuoåi (String ) : Chuoåi laø maûng moät chieàu kieåu kyù töï, trong

ñoù moãi kyù töï ñöôïc bieåu dieãn maèng maõ ascii. Chuoåi phaûi naèm trong hai daáu nhaùy ‘ ‘. Ví duï : Gaùn chuoåi Hello cho bieán str vôùi leänh laø

>>str = ‘Hello’ Haøm double vaø char :

double : chuyeån chuoåi kyù töï sang maõ soá ascii. Haøm coù cuù phaùp toång quaùt laødouble(string)

char : chuyeån chuoåi döôùi daïng maõ ascii sang daïng chuoái. Haøm coù cuù phaùp toång quaùt laøchar(string)

Ví duï : Chuyeån chuoåi Hello cho treân sang daïng maõ soá ascii vôùi leänh laø

Page 18: Chöông 2 : Laäp Trình M-file

>>str1 = double(str)Cho keát quaû laø

str1 = 72 101 108 108 111

Chuyeån chuoåi str1 döôùi daïng maõ soá ascii sang daïng chuoåi vôùi leänh laø>>char(str1)

Cho keát quaû laøans =Hello

Haøm strcmp vaø haøm strcat : strcmp : Haøm so saùnh hai chuoåi. Haøm coù cuù phaùp

toång quaùt laøstrcmp(string1,string2)

Haøm traû veà logical true(1) neáu hai chuoåi laø baèng nhau, maët khaùc traû veà logical false(0).

strcat : haøm noái hai hoaëc nhieàu chuoåi. Haøm coù cuù phaùp laøstrcat(str1,str2,str3, . . .)

Page 19: Chöông 2 : Laäp Trình M-file

Haøm isletter vaø haøm ispace : isletter : haøm xaùc ñònh chöõ caùi trong moät chuoåi

kyù töï. Cuù phaùp cuûa haøm laøisletter(string)

Haøm traû veà logical true(1) neáu ñoù laø chöõ caùi trong chuoåi; maët khaùc traû veà logical false(0).

ispace : haøm xaùc ñònh khoûang traéng trong moät chuoåi. Haøm coù cuù phaùp laøispace(string)

Haøm traû veà logical true(1) neáu ñoù laø khoûang traéng trong chuoåi; maët khaùc traû veà logical false(0).

Haøm int2str vaø haøm num2str : int2str : haøm laøm troøn soá thaønh soá nguyeân vaø

chuyeån soá ñöôïc laøm troøn naøy sang daïng chuoåi kyù töï. Haøm coù cuù phaùp laøint2str(number or array)

num2str : haøm chuyeån soá veà daïng chuoåi. Haøm coù cuù phaùp laønum2str(number or array)

Page 20: Chöông 2 : Laäp Trình M-file

5) Maûng Caáu Truùc :Döõ lieäu Matlab coù saùu kieåu döõ lieäu cô baûn

hay coøn goïi laø saùu lôùp döõ lieäu vôùi caáu truùc nhö hình

Array

char numeric

cell struct

double storage

sparse

user-object

Page 21: Chöông 2 : Laäp Trình M-file

Saùu lôùp döõ lieäu söû duïng trong Matlab : char, double, sparse, cell, struct vaø storage, moãi cuûa chuùng laø maûng nhieàu chieàu.

Lôùp array : lôùp döõ lieäu aûo. Lôùp char vaø double : lôùp thöôøng xuyeân

söû duïng. Lôùp numeric : lôùp döõ lieäu aûo. Lôùp cell : lôùp maûng döõ lieäu cell. Lôùp sparse : lôùp döõ lieäu ma traän thöa. Lôùp storage : lôùp aûo duøng caáp phaùt

boä nhôù cho bieán. Lôùp struct : lôùp döõ lieäu maûng caáu truùc. Lôùp user_object : lôùp döõ lieäu cho ngöôøi

söû duïng ñònh nghóa(daønh cho laäp trình höôùng ñoái töôïng).

Page 22: Chöông 2 : Laäp Trình M-file

Maûng caáu truùc : Maûng caáu truùc laø kieåu döõ lieäu coù theå chöùa

nhieàu kieåu döõ lieäu khaùc nhau. Moãi vuøng chöùa döõ lieäu khaùc nhau coù moät

teân rieâng ñöôïc goïi laø field_name. Cuù phaùp taïo maûng caáu truùc laø

struct_array_name.field_name = <expression>;Trong ñoù, expression coù theå laø chuoåi, ñaïi löôïng

voâ höôùng hoaëc maûng nhieàu chieàu. Taïo maûng caáu truùc:

patient.name = ‘John Doec’;patient.billing = 127.0;patient.test = [79 75 73;180 178 177.5;220 210 205];patient(2).name = “Ann Lane’;patient(2).billing = 28.0;patient(2).test = [68 70 68;118 118 119;172 170 169];

Page 23: Chöông 2 : Laäp Trình M-file

Truy caäp maûng caáu truùc : Xem thoâng veà maûng caáu truùc vôùi leänh laø

>>patient Hieån thò thoâng tin laø

patient = 1×2 struct with fieldsnamebillingtest

Xem noäi dung maûng caáu truùc vôùi leänh laø>> patient(1:2)

Xem phaàn töû thöù nhaát cuûa maûng caáu truùc vôùi leänh laø>>patient(1)

Xem phaàn töû thöù 2 vaø phaàn töû töông öùng cuûa tröôøng test vôùi leänh laø>> patient(2).test(2,2)

Löu yù : döõ lieäu maûng caáu truùc cho pheùp laäp trình höôùng ñoái töôïng trong Matlab.

Page 24: Chöông 2 : Laäp Trình M-file

5) Maûng cell : maûng cell laø moät kieåu döõ lieäu ñaëc bieät cuûa Matlab, trong ñoù moãi cell chöùa nhieàu kieåu döõ lieäu khaùc nhau. Maûng cell coù chæ soá cell laø (i,j) vaø chæ soá noäi dung laø

{i,j}. Cuù phaùp gaùn döõ lieäu cho maûng cell baèng chæ soá laø

cell_array_name(i,j) = { <celldata>}; Cuù phaùp gaùn döõ lieäu cho maûng cell baèng chæ soá noäi

dung laø cell_array_name{i,j} = <celldata>;

Ví duï : gaùn döõ lieäu cho maûng cell A baèng chæ soá laø>>A(1,1) = {[1 2 3;0 5 8;7 2 0]};>>A(1,2) = {‘Anne Amith’};>>A(2,1) = {3+7i};>>A(2,2) = {-pi:pi/10:pi};

Ví duï : gaùn döõ lieäu cho maûng cell A baèng chæ soá noäi dung laø>>A{1,1} = [1 4 3;0 5 8;7 2 0];>>A{1,2} = ‘Anne Smith’;>>A{2,1} = 3+7i;>>A{2,2} = -pi:pi/10:pi;

Page 25: Chöông 2 : Laäp Trình M-file

Truy caäp maûng cell : Xem thoâng tin veà maûng cell vôùi leänh laø

>>ACho keát quaû laø

[2×2 double] ‘Anne Smith’[3.0000 +7.0000i] [1×2 double]

Truy caäp maûng cell duøng chæ soá noäi dung vôùi leänh laø>> C = A{1,2}

Cho keát quaû laøC = ‘Anne Smith’

Truy caäp maûng cell baèng chæ soá maûng vôùi leänh laø>> C = A(1,2)

Cho keát quaû laøC =‘Anne Smith’

Huûy boû maûng cell vôùi leänh laø>>A = [ ]

Nguyen Thien Thanh
Page 26: Chöông 2 : Laäp Trình M-file

Ví duï :Laäp trình öùng duïng veõ caùc haønh tinh chuyeån ñoäng theo heä maët trôøi nhö hình

Page 27: Chöông 2 : Laäp Trình M-file

Ñeå laøm ñöôïc ñieàu ñoù, taäp caùc chöông trình caát trong caùc m-file ñöôïc moâ taû nhö hình

solar.m

data.m starts.m

finals.m

plots.m

repeats.m

names.m

idnums.

m

orbits12.m

periods.m

orbits34.m

ellipse.m

globals.m

prompts.

m

Solve_th.m

fzero.m

kepler.m

quad8 Radius_2

solar.m

data.m starts.m

finals.m

plots.m

repeats.m

names.m

idnums.

m

periods.m

ellipse.m

Page 28: Chöông 2 : Laäp Trình M-file

Script file solar.m vôùi noäi dung laø%solar.mglobalsdatastartsfinalsplotsrepeats

Script file globals.m vôùi noäi dung laø%globals.mglobal Name Period Orbitglobal Start_t Start_thglobal Final_t

Page 29: Chöông 2 : Laäp Trình M-file

Script file döõ lieäu data.m chöùa 5 cript file döõ lieäu khaùc ñoù laø

% Data.m idnums % Gaùn chæ soá cho caùc ñoái töôïngnames % Gaùn teân caùc ñoái töôïng periods % Chu kyø chuyeån ñoäng cuûa caùc haønh tinhorbits12 % Quõi ñaïo chuyeån ñoäng cuûa caùc haønh

tinhorbits34 % Quó ñaïo chuyeån ñoäng cuûa caùc haønh

tinh chieáu theo %goùc nghieâng Script file idnums.data

%idums.mMercury = 1;Venus = 2;Earth = 3;Mars = 4;Jupiter = 5;Saturn = 6;Uranus = 7;Neptune = 8;Pluto = 9;

Page 30: Chöông 2 : Laäp Trình M-file

Script file names.m%names.mName = '';Name(Mercury,:) = 'Mercury';Name(Venus, :) = 'Venus ';Name(Earth, :) = 'Earth ';Name(Mars, :) = 'Mars ';Name(Jupiter,:) = 'Jupiter';Name(Saturn, :) = 'Saturn ';Name(Uranus, :) = 'Uranus ';Name(Neptune,:) = 'Neptune';Name(Pluto, :) = 'Pluto ';

Script file periods.m%period.mPeriod = zeros(9,1);Period(Mercury) = 0.24;Period(Venus) = 0.62;Period(Earth) = 1.00;Period(Mars) = 1.88;Period(Jupiter) = 11.86;Period(Saturn) = 29.46;Period(Uranus) = 84.0;Period(Neptune) = 164.8;Period(Pluto) = 247.7;

Page 31: Chöông 2 : Laäp Trình M-file

Caùc haønh tinh chuyeån ñoäng theo quó ñaïo hình ellipse nhö hình

C + d = constant

2bf

dc

þ

f = ea

f2 = a2 – b2 2a

Page 32: Chöông 2 : Laäp Trình M-file

Script file orbits12.m thieát laäp quan heä giöõa eccentricity(e) ôû coät thöù nhaát vaø minor axis (b) ôû coät thöù 2 cuûa maûng.

%orbits12.mOrbit = zeros(9,4);Orbit(Mercury,1:2) = [0.39, 0.206];Orbit(Venus, 1:2) = [0.72, 0.007];Orbit(Earth, 1:2) = [1.00, 0.017];Orbit(Mars, 1:2) = [1.52, 0.093];Orbit(Jupiter,1:2) = [5.20, 0.048];Orbit(Saturn, 1:2) = [9.54, 0.056];Orbit(Uranus, 1:2) = [19.19, 0.047];Orbit(Neptune,1:2) = [30.07, 0.009];Orbit(Pluto, 1:2) = [39.46, 0.249];

Scipt file orbits34.m chöùa goùc quay quanh truïc majar cuûa moãi haønh tinh vaø ñoä nghieâng.

%orbits34.mOrbit(Mercury,3:4) = [0.00, 7.0];Orbit(Venus, 3:4) = [0.00, 3.4];Orbit(Earth, 3:4) = [0.00, 0.0];Orbit(Mars, 3:4) = [0.00, 1.9];Orbit(Jupiter,3:4) = [0.00, 1.3];Orbit(Saturn, 3:4) = [0.00, 2.5];Orbit(Uranus,3:4) = [0.00, 0.8];Orbit(Neptune,3:4) = [0.00, 1.8];Orbit(Pluto, 3:4) = [0.00, 17.1];

Page 33: Chöông 2 : Laäp Trình M-file

Script file starts.m löu tröõ vò trí goùc baét taïi thôøi ñieåm start_t cuûa caùc haønh tinh.

%starts.mStart_t = 1995.0 +3/365;Start_th = zeros(9,1);Start_th(Mercury) = 345.7083;Start_th(Venus) = 138.8194;Start_th(Earth) = 102.1532;Start_th(Mars) = 119.2770;Start_th(Jupiter) = 242.7067;Start_th(Saturn) = 348.7888;Start_th(Uranus) = 291.6482;Start_th(Neptune) = 293.7496;Start_th(Pluto) = 231.6706;Start_th = Start_th*pi/180;

Page 34: Chöông 2 : Laäp Trình M-file

Script file finals.m%finals.mFinal_t = prompts;Final_th = zeros(9,1);Final_th(Mercury) = solve_th(Mercury);Final_th(Venus) = solve_th(Venus);Final_th(Earth) = solve_th(Earth);Final_th(Mars) = solve_th(Mars);Final_th(Jupiter) = solve_th(Jupiter);Final_th(Saturn) = solve_th(Saturn);Final_th(Uranus) = solve_th(Uranus);Final_th(Neptune) = solve_th(Neptune);Final_th(Pluto) = solve_th(Pluto);Final_th

Page 35: Chöông 2 : Laäp Trình M-file

Script file prompts.c%prompts.mfunction Final_t = promptsglobalsdisp('..............................................');disp([' Start time is : ', num2str(Start_t,10)]);disp('...............................................');disp(['Final time can be a number : ', num2str(Start_t+5)]);disp(['or it can be an expression : ','Start_t+5']);Final_t = input('Enter Final time : ');disp('................................................');disp([' Final time is : ',num2str(Final_t,10)]);

Function file sove_th.m function f_th = solve_th(id)global cur_idcur_id = id;th_guess = pi;f_th = fzero('kepler',th_guess);

Page 36: Chöông 2 : Laäp Trình M-file

Leänh fzero goïi haøm kepler vôùi ñoái soá vaøo cuûa haøm ñeå giaûi goùc vò trí Final_th cuûa caùc haønh tinh vôùi caùc phöông trình laø

0)( Tt

abAKepler final

0

)(21 2

Periodtt

ab

drStartFinal

final

start

)cos(1)1()('

angleeeare

Page 37: Chöông 2 : Laäp Trình M-file

Function file kepler.m function diff = kepler(Final_th)global cur_idglobalstol = 1e-6;A = (1/2)*quad8('radius_2',Start_th(cur_id),Final_th,tol);a = Orbit(cur_id,1);e = Orbit(cur_id,2);b = a*sqrt(1-e^2);t = Final_t - Start_t;T = Period(cur_id);diff = A/(pi*a*b) - t/T;

Function file radiuus_2.m traû veà r(þ)2 trong haøm laáy tích phaân quad8.

function r_2 = radius_2(th)global cur_idglobalsa = Orbit(cur_id,1);e = Orbit(cur_id,2);angle = Orbit(cur_id,3);r = a*(1-e^2)./(1 - e*cos(th - angle));r_2 = r.^2;

Page 38: Chöông 2 : Laäp Trình M-file

Script file plots.m veõ quó ñaïo chuyeån ñoäng cuûa caùc haønh tinh theo heä maët trôøi.

%plots.mfor ifig = 1:2 figure(ifig) if ifig == 1, from = Mercury; to = Mars; end if ifig == 2, from = Mars; to = Pluto; end for id = from:to a = Orbit(id,1); e = Orbit(id,2); angle = Orbit(id,3); ellipse(a,e,0,2*pi,angle) hold on h = ellipse(a,e,Start_th(id),Final_th(id),angle); set(h, 'LineWidth',4.0) th = 3*pi/2; r = a*(1 - e^2)./(1 - e*cos(th - angle)); [x,y] = pol2cart(th,r); text(x,y,Name(id, :)) end hold off axis equal axis('square')end

Page 39: Chöông 2 : Laäp Trình M-file

Function file ellipse.m veõ hình ellipse.function [o1, o2] = ellipse(a,e,th1,th2,angle,x1,y1,npts)if nargin < 3, th1 = 0.0; endif nargin < 4, th2 = 2*pi; endif nargin < 5, angle = 0.0; endif nargin < 6, x1 = 0.0; endif nargin < 7, y1 = 0.0; endif nargin < 8, npts = 1 + 360*(th2 - th1)/(2*pi);endif nargin < 2 | nargin > 8 error('Wrong number of input argument')end th = linspace(th1,th2,npts); r = a*(1 - e^2)./(1 - e*cos(th - angle)); [x,y] = pol2cart(th,r); x = x + x1; y = y + y1; if nargout == 0 plot(x,y,'-'); end if nargout == 1 o1 = plot(x,y,'-'); end if nargout == 2 o1 = x; o2 = y; end if nargout > 2 error('Wrong number of output arguments') end

Page 40: Chöông 2 : Laäp Trình M-file

Script file repeats.m thöïc hieän laëp laïi neáu caàn.%repeats.manother = input(['Do you wish to trace another Orbit ?

[y/n]'],'s');while strcmp(another, 'y') cont = input(['Do you wish to start from where you left off

[y/n]'],'s'); if strcmp(cont,'y') Start_t = Final_t; Start_th = Final_th; end Finals Plots another = input(['Do you wish to trace another Orbit

?[y/n]'],'s');end

Chaïy chöông trình goû leänh solar.