Danh mục

matlab_toan_tap_9

Số trang: 10      Loại file: pdf      Dung lượng: 101.90 KB      Lượt xem: 6      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu matlab_toan_tap_9, kỹ thuật - công nghệ, điện - điện tử phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
matlab_toan_tap_9 81Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com % (H1 help line) %P=LOAN(A,R,M) computes the monthly payment on a loan %amount of a, having an annual intereat rate of R, % to be paid off in equal amounts over M months. % %[P,S]=LOAN(A,R,M) also returns % an amortization table S, %which is an M-by-4 matrix % where S(:,1)=Payment Number, %S(:,2)=Remaining Balance, S(:,3)=Interest Paid, and %S(:,4)=Principle Paid. % %If no output arguments are provided % the table is displayed. %Start with some error checking if nargin 82Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com disp([Number of month = int2str(m)]) disp([Payment = num2str(p)]) disp( ) disp( Amortization Schedule) disp( Payment Balance Interest Principle) fprintf( %5.0f %12.2f %12.2f %12.2f\n, s) % better formatting else % two output arguments requested P=p; S=s; end VÝ dô: Gi¶i m· mµu trªn c¸c ®iÓn trë VÊn ®Ò: Gi¸ trÞ cña mét ®iÖn trë dïng trong m¹ch ®iÖn ®−îc tÝnh th«ng qua c¸c v¹ch mµu in trªn th©n cña nã. §èi víi mét ®iÖn trë víi ®é chÝnh x¸c lµ 5% th× cã 3 d¶i mµu, t¹m gäi lµ A, B, C. Gi¸ trÞ sè ®−îc g¸n cho mçi mµu ®−îc tÝnh nh− sau: Mµu §en N©u §á Vµng Lôc Lam Trµm TÝm X¸m Tr¾ng Gi¸ trÞ 0 1 2 3 4 5 6 7 8 9 NÕu A, B, C lµ c¸c gi¸ trÞ cña c¸c mµu trªn gi¶i mµu th× gi¸ trÞ cña c¸c ®iÖn trë lµ: R = (10.A + B).10C Sö dông c¸c th«ng tin nµy, h·y t¹o mét M_file tr¶ vÒ gi¸ trÞ cña ®iÖn trë øng víi bÊt kú mét ®iÖn trë chuÈn nµo. Gi¶i ph¸p: VÊn ®Ò nµy yªu cÇu mét chuçi c¸c thao t¸c vµ so s¸nh ®Ó thùc hiÖn sù chuyÓn ®æi trong b¶ng trªn. Gi¶i ph¸p cña MATLAB lµ: function r=resistor(a, b, c) %RESISTOR(A, B, C) Resistor value from color code. %RESISTOR(a, B, C) returns the resistace %value of resistor %given its three color bands, A, B, C. %A, B, C must be one of the %following character strings: % %black, brown, red, orange, yellow, %green, blue, violet, gray, white % first some error checking if nargin~=3 error(Three input arguments required) end if ~ischar(a)|~ischar(b)|~ischar(c) error(Inputs Must be Character X©us) end %now solve problem vals=zeros(1,3); % string cell array of three inputs abc={a,b,c}; % tring cell aray ß thrª input 83Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com for i=1:3 %do each color band in turn band=lower(abc(i)); %get (i)th input and make lower case if strncmp(band,bla,3) % black (compare min # of) vals(i)=0; % chars for unique match) elseif strncmp(band,br,2) %brown vals(i)=1; elseif strncmp(band,r,1) %red vals(i)=2; elseif strncmp(band,o,1) %orange vals(i)=3; elseif strncmp(band,y,1) %yellow vals(i)=4; elseif strncmp(band,gre,3) %green vals(i)=5; elseif strncmp(band,blu,3) %blue vals(i)=6; elseif strncmp(band,v,1) %violet vals(i)=7; elseif strncmp(band,gra,3) %gray vals(i)=8; elseif strncmp(band,w,1) %white vals(i)=9; else error([Unknown Color Band.]) end end if vals(1)==0 error(First Color Band Cannot Be Black.) end r=(10*vals(1)+vals(2))*10^vals(3); Sö dông hµm nµy cho mét vµi vÝ dô: >> resistor(brown, black, red) ans= 1000 ------------------------oOo----------------------- ch−¬ng 13 PH¢N TÝCH D÷ LIÖU Bëi v× MATLAB lµ mét øng dông h−íng ma trËn nªn nã dÔ dµng thùc hiÖn c¸c ph©n tÝch thèng kª trªn c¸c tËp d÷ liÖu, trong khi theo mÆc ®Þnh MATLAB coi c¸c tËp d÷ liÖu ®−îc l−u tr÷ trong c¸c m¶ng cét, viÖc ph©n tÝch d÷ liÖu cã thÓ thùc hiÖn theo bÊt cø chiÒu nµo. §ã lµ trõ khi ®−îc chØ ®Þnh theo mét c¸ch kh¸c, c¸c cét cña mét m¶ng d÷ liÖu thÓ hiÖn c¸c th«ng sè ®o kh¸c nhau, mçi hµng thÓ 84Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com hiÖn mét gi¸ trÞ mÉu cña c¸c th«ng sè ®o ®ã. VÝ dô gi¶ sö nhiÖt ®é ban ngµy (tÝnh theo ®é C) cña 3 thµnh phè tÝnh trong mét th¸ng (31 ngµy ®−îc ghi l¹i vµ g¸n cho mét biÕn lµ temps trong mét script M_file, khi ch¹y M_file th× gi¸ trÞ cña temps ®−îc ®a vµo m«i tr−êng MATLAB, thùc hiÖn c«ng viÖc nµy, biÕn temps chøa: >> temps temps= 12 8 18 15 9 22 12 5 19 14 8 23 12 6 22 11 9 19 15 9 15 8 10 20 19 7 18 12 7 18 14 10 19 11 8 17 9 7 23 8 8 19 15 8 18 8 10 20 10 7 17 12 7 22 ...

Tài liệu được xem nhiều:

Tài liệu có liên quan: