You are on page 1of 4

Matlab Final

Name and Surname: Signature:

Duration:75 min
ANSWER KEY ID: GRADE:

09.06.2009

Q1. Write short answers for the following questions : a) (5 point ) What is the effect of the format short command? FORMAT SHORT : Scaled fixed oint format with ! digits"

!) (1" point ) Write a Matla# function $m file% to e&aluate the function ' ( sin)$x)% where * x k and to lot the function when + is gi&en #' user" ,f + is negati&e- rint an error on the screen"
function y(k) if nargin<1 | k<=0, error('check the data'), end; x=0:0.01:k; y=sin(x.^ ).^ ; !"ot(y)

function check1(#) if si$e(#)%=&, error('this #ector does not ha#e & co'!onenets'), end; end

#) (5 point ) Write a m file called .chec+/0 that ta+es a &ector as in ut and rints an error message for all &ectors that do not ha&e exactl' three com onents"

d) (5 point ) A student has the following m file function: function m'fun/$a% reci rocal(/1a2 result()3reci rocal ,n command window- the student t' es the following 44a(52 m'fun/$a%- reci rocal What &alues does Matla# rint after these commands ? result ( *"6667 ??? 8ndefined function or &aria#le 9reci rocal9" e) (5 point ) Write the commands to lot the functions ' &ersus x and : &ersus x on the same axes" lot$x-'%2 hold2 lot$x-:%

$age /

Q%. (15 point ) a) ;raw a S,M8<,=> model which shows the solution of the s'stem

x + ) y = ! ) x y = 5"

(1" point ) !) ?x lain the following terms : ie5$x%- s'ms - ex and- su#function- call#ac+ function" @,?5 5A; ie chart" SBMS ShortAcut for constructing s'm#olic o#Cects" ?D@A=; ex and records into swee s with si:e s ecified in t S8EF8=FT,O= ,n a mAfile- su#functions are functions that constructed for local use FA<<EAF> F8=FT,O= ,n G8,- Fall#ac+ functions defines what the o#Cect does"

$age )

Q&.

(%" point ) a) Write a com lete Ma le rogram to sol&e the following ro#lem: An o#Cect has #een thrown &erticall' from the ground with an initial s eed- H*(5! m1sec" ) Assume that g =/*m 1 sec and neglect air friction" Fom ute and dis la' the total fl'ing time of the o#Cect Fom ute and dis la' the maximum height of the o#Cect Fom ute and dis la' the height of o#Cect at t(! sec" Bou can use the following formulae when necessar':
V = V* g t

and

y = V* t

/ gt) )

final:=proc() local Vo, g, tmax, t, hmax, hatfive; Vo:=35; g:=10; tmax:=Vo/g; t:=tmax*2; print( !otal"fl#ing"time"i$ , t); hmax:=Vo*tmax%1/2*g*tmax&2; print( 'axim(m"height"i$ , hmax); hatfive:=Vo*5%1/2*g*5&2; print( )eight"at"five"$ec"i$ , hatfive); en*;

$age 5

Q'. (5point ) a) Gi&e the out ut for the following Ma le codes" ?x lain 'our result" a:=0; +:=1; for i from 1 +# 2 to 5 *o c:=(a,+)/2; if c-3/. then a:=c el$e +:= c fi; o*;

a :( *
b :( / c :( c :( c :( / ) 5 I ! J

(%" point ) !) Write a m"file- which founds how man' digits of whole num#er and decimal num#er are there in a num#er gi&en #' user" For exam le : /)5I"!67 has I digits of whole num#er and 5 digits of decimal num#er" *"5) has / digit of whole num#er and ) digits of decimal num#er"
function digit(n); k=0; n=a(s(n); n1=n; )hi"e cei"(n)*n%=0; n=10+n k=k,1; end; s=1; )hi"e cei"(n1)-=10; n1=n1.10; s=s,1; end; the/nu'(er/of/)ho"e/digits=s, the/nu'(er/of/digits/in/deci'a"/!art=k,

$age I

You might also like