
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Assignment include 3 part for begginner student
Typology: Assignments
1 / 32
This page cannot be seen from the preview
Don't miss anything!
Chapter 1 : Exercise 1 :Scalarquantitiesandvariables Answer: a= 2 ; b= 3 ; y=a+ 1 y= 3 x=a+b x= 5 c= 4 ; a*(b+c) ans= 14 a/(b+c) ans=
Answer: a= 1 : 4 ; b= 2 : 4 ; disp(a) 1 2 3 4 isempty(a) ans= 0 isequal(a,b) ans= 0 isinteger(b) ans= 0 isinteger(int 8 (b)) ans= 1 isvector(a) ans= 1 isscalar(a) ans= 0 issparse(a) ans= 0 size(a) ans=
Exercise 6 :Calculatethefollowingexpressions formatshortG x=sin(pi/ 3 ); formatshortG x x=
b) 2 *sin( 1. 4 ) ans=
randi([ 3 , 6 ]) ans= 6 randi([ 3 , 6 ]) ans= 5 randi([ 3 , 6 ]) ans= 3 randi([ 3 , 6 ]) ans= 4 PRACTICE1. 2 .Generatearandom
xor('c'=='d'- 1 , 2 < 4 ) ans= 0 10 > 5 > 2 ans= 0 CH- 2 Practicethefollowingquestions 1 .Whathappensifaddingthestepvaluewouldgobeyondtherangespecifiedbythelast,forexample 1 : 2 : 6. Answer:
pvec= 1 : 2 : 6. pvec= 1 3 5 2 .Howcanyouusethecolonoperatortogeneratethevectorshownbelow? Answer: pvec= 9 :- 2 : 1 pvec= 9 7 5 3 1 Practice 2. 1 2 .Thinkaboutwhatwouldbeproducedbythefollowingsequenceofstatementsandexpressions,and thentypethem intoverifyyouranswers: Answer: pvec= 3 : 2 : 10 pvec= 3 5 7 9 pvec( 2 )= 15 pvec=
pvec( 7 )= 33 pvec= 3 1 5 7 9 0 0 3 3 pvec([ 2 : 47 ]) ans= 15 7 9 3 3 linspace( 5 , 11 , 3 ) ans= 5 8 1 1 logspace( 2 , 4 , 3 ) ans= 100 1000 10000 Practice 2. 2 3 .Thinkaboutwhatwouldbeproducedbythefollowingsequenceofstatementsandexpressions,and thentypethem intoverifyyouranswers. Answer: mat=[ 1 : 3 ; 3 : 5 ; 5 : 7 ] mat= 1 2 3 3 4 5 5 6 7 zeros(size(mat)) ans= 0 0 0 0 0 0 0 0 0
numel(mat) ans= 12 v=mat( 3 ,:) v= 5 4 3 3 3 v(v( 2 )) ans= 33 v( 1 )=[] v= 4 3 3 3 reshape(mat, 2 , 6 ) ans= 1 5 9 3 3 1 1 44 2 4 2 8 3 3 Chapter 3 :Looping %%A)fact= 1 ; fori= 2 : 6 fact=fact*i end fact= 2 fact= 6 fact=
fact= 120 fact= 720 clearall closeall %%functionrunsum =sumnnums(n) runsum =2; n= 1 : 10 ; fori=1:n; inputnum =input('Enteranumber:'); runsum =runsum+inputnum end end Answer Enteranumber: 3 runsum = 5 ans= 5 clearall closeall %%total= 0 ; forn= 1 : 6 ; total=total+ 2 ^n; end Answer: 126 total= 0 ; fori= 3 : 7 ; total=total+i^ 3 end total= 775 %% %%maxN=input('Enterthemaximum valueofNrequired:'); I( 1 )= 1 ^ 2 ; forN= 2 :maxN I(N)=I(N- 1 )+N^ 2 ; end
x=input('plaseenterx:'); ifx>= 0 &&x<= 1 f=x elseifx> 1 &&x<= 2 f= 2 - x else f= 0 end Ans: plaseenterx: 1. 5 f=
Example# 2 Plotthegraphandidentifythezero’svalues f(x)=sin( 10 x)+cos( 3 x) code: x=linspace( 3 , 6 ); y=sin( 10 .x)+cos( 3 .x); plot(x,y) gridon Output: Thezeroisnear 3. 25 , 3. 4 , 3. 75 , 4. 25 , 4. 70 , 5. 2 , 5. 23 ,andanothernear 5. 68 ExamplesonFindingrootsofpolynomials Example# 1
gridon end Example#2Determinetheinitialestimatesforthezerosofthefunctionf(x)=xsinx–x^ 0. 5 code: =@(x)x.*sin(x)-x.^ 0. 5 ; fzero(f, 0 ) output: ans= 0 ExamplesonFixedPointIterationmethod Example# 1 FixedpointIterationmethodtofindingroots f(x)=2-x+ln(x) x=e^(x- 2 )xn+1=2+ln(x) TosolvetherootbyMs-excelasfollows; Iteration X=e^(x- 2 )xn+1=2+ln(x) 1 1 1 2 0. 3678794412 3 0. 1955145342. 693147181 4 0. 1645591062. 990710465 5 0. 1595431453. 095510973 6 0. 1587448863. 129952989 7 0. 1586182173. 141017985 8 0. 1585981263. 144546946 9 0. 158594943. 145669825
2 ndSolution: code:forx=2+sin(x) Example#2 FixedpointIterationmethodtofindingroots f(x)=e^x-x xn+1=e^xn Iteration X 1 0 2 1 3 0. 367879441 4 0. 692200628 5 0. 500473501 6 0. 606243535 7 0. 545395786 8 0. 579612336 9 0. 560115461