0 views

Uploaded by khicom

Matlab exercise

save

You are on page 1of 8

Worksheet 2A

**Name: Yen Pham
**

Section: C2

**Instructions: The minimum set for this worksheet is all Problems. Note: the important
**

thing to record is the MATLAB expression(s) that you use to solve these problems.

1) Generate a

random real number in the range from 0 to 1

>> rand

ans =

0.8147

random real number in the range from 20 to 50

>> rand*(50-

20)+20

ans =

47.1738

random integer in the range from 0 to 11

>> randi([0,11])

ans =

3

random integer in the range from 50 to 100

>>

randi([50,100],1)

ans =

54

4 x 4 matrix of random real numbers, each in the range from 0 to 1

>> rand(4)

ans =

**0.2785 0.1576 0.8003 0.7922
**

0.5469 0.9706 0.1419 0.9595

0.9575 0.9572 0.4218 0.6557

0.9649 0.4854 0.9157 0.0357

each in the range from 0 to 100 >> randi([0.100].10) ans = 1 2 3 4 5 6 7 8 9 10 >> 2:5:12 ans = 2 7 12 >> linspace(2.12. >> 3*10^5==3e5 ans = 1 . 5 x 2 matrix of random integers.10.2) ans = 68 96 66 35 17 59 12 23 50 76 2) Create the following vectors twice.3) ans = 2 7 12 3) Use the equality operator to verify that 3*10^5 is equal to 3e5.5. using linspace and using the colon operator: 1 2 3 4 5 6 7 8 9 10 2 7 12 Solution: >> 1:10 ans = 1 2 3 4 5 6 7 8 9 10 >> linspace(1.

3. find a simple expression that will transform the matrix into each of the following: 2 7 5 5 8 3 >> mymat' ans = 2 7 5 5 8 3 2 5 7 8 5 3 >> reshape(mymat.4) Use the equality operator to verify the value of log10(10000).7:-2:3] mymat = 2 5 8 7 5 3 Using this matrix. >> 4==log10(10000) ans = 1 5) Create a matrix variable “mymat” which stores the following: mymat = 2 5 8 7 5 3 >> mymat=[2:3:8.2) ans = 2 5 7 8 5 3 .

8 5 2 3 5 7 >> fliplr(mymat) ans = 8 5 2 3 5 7 8 3 5 5 2 7 >> rot90(mymat) ans = 8 3 5 5 2 7 2 5 8 2 5 8 7 5 3 7 5 3 >> repmat(mymat.2) ans = 2 5 8 2 5 8 7 5 3 7 5 3 .1.

1653 0.9694 0.4802 -2.0000 7) The built-in function clock returns a vector that contains 6 elements: the first three are the current date (year.6) Create a vector x which consists of 20 equally spaced points in the range from – to +.8188 -1.1416 -2.1646 0. but all others are integers.0000 -0.1653 0.20) x = Columns 1 through 6 -3.7357 0. store the first three elements from this variable in a variable “today” and the last three elements in a variable “now”.pi. >> myc=clock . The seconds is a real number.8188 2.4759 Columns 13 through 18 0.9158 -0.8109 3.1646 0. Create a y vector which is sin(x).8372 0. >> x=linspace(-pi.4881 1.4960 Columns 13 through 18 0.4881 Columns 7 through 12 -1. and seconds.3247 -0.9966 Columns 7 through 12 -0.9694 -0.1416 >> y=sin(x) y= Columns 1 through 6 -0. Store the result from clock in a variable called “myc”. Then.8109 -2.7357 -0.8267 1.6142 -0.8267 -0. Use the fix function on the vector variable “now” to get just the integer part of the current time.8372 -0.1574 1.6142 Columns 19 through 20 0.1495 2.9158 0. month.3247 0. minutes.1574 -0.1495 -1.4759 -0. day) and the last three represent the current time in hours.4802 Columns 19 through 20 2.9966 0.4960 -0.

and rot90. flipud.0090 0.3754 8) Create a 2 x 3 matrix variable mat.0000 37.0120 0.0150 0.0e+03 * 2.0370 0. In how many different ways can you reshape it? >> mat=randi([50.0000 53.3) mat = 75 120 146 101 139 105 >> fliplr(mat) ans = 146 120 75 105 139 101 >> flipud(mat) ans = 101 139 105 75 120 146 >> flip(mat) ans = 101 139 105 75 120 146 >> rot90(mat) .myc = 1. Pass this matrix variable to each of the following functions and make sure you understand the result: fliplr.2.150]. flip.0534 >> today=myc(1:3) today = 2016 9 12 >> now=myc(4:6) now = 15.0160 0.

3.120].2) ans = .1) ans = 75 101 120 139 146 105 >> reshape(mat.6. Pass it to the repelem function and to the repmat function and make sure you understand the difference.3.6) ans = 75 101 120 139 146 105 >> reshape(mat.1.2) ans = 75 139 101 146 120 105 >> % We can reshape the matrix 'mat' in 3 different ways 9) Find the sum 3+5+7+9+11. >> sum(3:2:11) ans = 35 10) Create a matrix variable of random integers.4) mat = 54 79 70 119 78 96 80 61 87 94 51 57 >> repmat(mat. >> mat=randi([50.ans = 146 105 120 139 75 101 >> reshape(mat.1.

2) ans = 54 54 79 79 70 70 119 119 78 78 96 96 80 80 61 61 87 87 94 94 51 51 57 57 >> %'repmat(A.n. . That is.1.m) replicates A to create a new matrix %containing a n-by-m block of each element of A 11) Are there equivalents to intmin and intmax for real number types? Use help to find out.n.m)' replicate the entire array to % create a new matrix consisting n-by-m tiling of copies of A >> % 'repelem(A. 54 79 70 119 54 79 70 119 78 96 80 61 78 96 80 61 87 94 51 57 87 94 51 57 >> repelem(mat. intmin(‘int32’) and intmax(‘int32’) respectively are the same as intmin and intmax. Yes. There is a equivalent to intmin and intmax.

- ArrayUploaded byBhanu Bhaskar
- Advanced Higher Maths Exam 2015Uploaded byStephenMcI
- Class Xi PracticalsUploaded byVikas Saxena
- foxproUploaded bydavy_7569
- Matlab BasicsUploaded byEr Manish
- CAPE Pure Mathematics (2016) U2 P1 AnswersUploaded byDaveed
- CSC113 Solution 2009Uploaded bys_nimalan
- ael2002Uploaded bymagic1111
- CA141Uploaded byMatt Collins
- Abinitio VectorsUploaded byPindiganti
- 04.07103006Uploaded byayoubhajjaji
- matlab-SC08%20HPCC%20Presentation.pdfUploaded byEl Tripi
- Mathematica - MathUploaded bycarmo-neto
- Sample FinalUploaded byKingUmar
- List of Experiments ItpUploaded byprateekrbhutani
- FOXPRO MCQ QUESTIONUploaded bysanku gupta
- Advanced Engineering Mathematics 3rd Ed - Merle C. Potter Et Al. (OUP, 2005)Uploaded byMarcelo Fabiano
- LECT12.pdfUploaded byAnirodh
- MELJUN CORTES ITC 18Uploaded byMELJUN CORTES, MBA,MPA
- Arrays-2[2]Uploaded byAhsan Tariq
- Cusparse LibraryUploaded bynovavoid_18337

- Phys 1442Uploaded bykhicom
- WS3A Scripts IO PlotsUploaded bykhicom
- m820-sol-2011.pdfUploaded bykhicom
- Quiz5_A35solUploaded bykhicom
- Solutions01_2017Uploaded bykhicom
- Summary 01Uploaded bykhicom
- 2018_HW1(3)Uploaded bykhicom
- Lec 1 - LaptopsUploaded bykhicom
- AWS Customer AgreementUploaded bykhicom
- Lecture 2Uploaded bykhicom
- Eet 1240Uploaded bykhicom
- l02_verilog.pdfUploaded bykhicom
- Introduction to Electronics DesignUploaded bykhicom
- Eet 1240 OutlineUploaded bykhicom
- setting-up-a-raspberry-pi-as-a-wifi-access-point.pdfUploaded bykhicom
- Brach With DragUploaded bykhicom
- Variable End PointUploaded bykhicom
- PHY2028 - Getting Started With SpiceUploaded bykhicom
- 20 Phrases for Closing an Email _ Matt Schmid _ Pulse _ LinkedInUploaded bykhicom
- Volcab 4 UploadUploaded bykhicom
- ECE.undergrad.syllabus.ec455.2015Uploaded bykhicom

- PROYECTO-DE-INVESTIGACIÓN-CALCULO-III..docxUploaded byalexander silva diaz
- INTEGRALES.docxUploaded byCristian Daniel
- Spline PrimerUploaded byVeronica Navia
- Polinómios (teoria)Uploaded byVictor Nascimento
- SISTEMA DE ECUACIONESUploaded byAndresPomaTorres
- FORMULARIO PREUNIVERSITARIOUploaded byDario Al Congreso
- S. V. Astashkin and L. Maligranda- On Interpolation in Lp SpacesUploaded byJutyyy
- Factor Comun Explicacion Y EjerciciosUploaded byDayan ҺệŗŘēŖÂ яŨłż
- Lautman,A.: Mathematics, Ideas and the Physical Real_[2011]Uploaded bypeterpan1
- Seminario 1. Matrices y SELUploaded byJuanMiguelOrozcoSanchez
- Exercicios Radiciação 9° anoUploaded byPedroHenriqueBrito
- Ac Naturales y Divisivilidad SantillanaUploaded byEVA
- EVEN12Uploaded byEliana Margarita Moscote
- ODE StabilityUploaded bybaraksh4
- Grade 7 Term 2 Social ScienceUploaded byVarshLok
- Lab de Control 1 SegundoUploaded byCarlos J Duran Fore
- Solucion de Ecuaciones Lineales (5)Uploaded byOscar Gayosso
- 7 Division de PolinomiosUploaded bysantiago
- PolinomiosUploaded byDaymar Medero
- MII T1 2015.pdfUploaded byManuel Lucas
- Vector Finite Elements and C++Uploaded byJunhua Wang
- Simple_circle_fitting.pdfUploaded byOsolemio Mer
- Math2320 Review for Final AnswersUploaded by嘉雯吳
- 04 ÁLGEBRA - Compendio N° 02 - Ciclo Normal 2007-I.pdfUploaded bySergio Martinez
- Guia 04 Fmm112 (Sem 1)Uploaded byCatalina Jofré
- L06 Gradient and Directional Derivatives_annotated 09032012Uploaded byjared_christianhadynata_liu
- 70 Vector & 3d Part 3 of 6Uploaded byLuis Anderson
- 3. Polinomios de Interpolación de NewtonUploaded byfernando1010
- Capitulo 15 Analisis VectorialUploaded byErik Villegas
- Solving Literal EquationsUploaded byGene