Large List Of Exercise: Start Doing Now! 1 – 35: Basic .

2y ago
18 Views
2 Downloads
4.93 MB
44 Pages
Last View : 23d ago
Last Download : 3m ago
Upload by : Kaden Thurman
Transcription

Introduction to MATLAB – Step by Step ExerciseLarge list of exercise: start doing now!1 – 35: Basic (variables, GUI, commandwindow, basic plot, for, if, functions)36 – 40: Medium (functions)41 – 45: Medium (matrices)46 – 51: Medium (plot)52 – 55: Medium (integration)56 – 60: Advanced (combined problems)

Introduction to MATLAB – Step by Step Exercise1. Open MATLAB(student AMO/AIR)2. Make sure that you recognize the Graphic UserInterface (GUI)

Introduction to MATLAB – Step by Step Exercise3. Look for the command window, and use it as acalculator: 2 22 * 222

Introduction to MATLAB – Step by Step Exercise4. Create variables at the command window: a 2b 3a bfirst string 'My name is 'second string umanyyearsago' first string second string

Introduction to MATLAB – Step by Step Exercise5. Create variables based on other variables: c a * 2d cos(b)e c dr 5A 2 * pi * rC 2 * pi * rx 0curve f sin(x) cos(x/3 1)

Introduction to MATLAB – Step by Step Exercise6. Create vectors: vector 1 [1 2 3 4 5 6 7 8 9 10]vector 2 [12 13 14 15 16 17 8767826264]7. Operation with vectors: vec 1 [1 2 3]vec 2 [7 8 9]vec 1 10vec 1 vec 2vec 1 - vec 2times(vec 1, vec 2)

Introduction to MATLAB – Step by Step Exercise8. Create column vectors colu 1 [1; 2; 3; 4; 5]colu 2 [23; 24; 25; 26]colu 3 ['aa'; 'bb'; 'cc'; 'dd']9. Other ways to create vectors: z zeros(5,1)zz zeros (1, 5)zzz [0: 1:10]zzzz [-8763: 430.2265 : 5634.23]

Introduction to MATLAB – Step by Step Exercise10. Creating Matrices: matr 1 [1 2 3; 4 5 6; 7 8 10]matr 2 ['lala ' 'lele '; 'lili ' 'lolo'; 'lulu ' 'lålå ']11. Operation with Matrices: matr 1 10sin(matr 1)matr 1'inv(matr 1)identity matrix matr 1 * inv(matr 1)element multiplication matr 1.*matr 1

Introduction to MATLAB – Step by Step Exercise12. Accessing elements in the Matrix: matr 1(1,2)matr 1(8)matr 1(1:3,2)matr 1(3,:)13. Check that your variables are at the workspace:

Introduction to MATLAB – Step by Step Exercise14. Create and save a script (no spaces, MATLABfolder):

Introduction to MATLAB – Step by Step Exercise14. Start your script by clearing the variables anssumming 2 2:1. clear2. 2 215. Run your script and check the answer (ans) onthe command window:

Introduction to MATLAB – Step by Step Exercise16. Create a vector in your script with a list of dates:1. clear2. dates [1015 1066 1660 1814 1905 2014]17. Realize that, by putting ; at the end of the line thecommand does not appear at the command window:1. clear;2. dates [1015 1066 1660 1814 1905 2014];

Introduction to MATLAB – Step by Step Exercise18. Sum up all the ages:1. clear2. dates [1015 1066 1660 1814 1905 2014];3. sum all sum(ages);19. Save the number of dates inside the vector"dates" into a variable ":1.2.3.4.clear;dates [1015 1066 1660 1814 1905 2014];sum all sum(dates);how may dates length(dates);

Introduction to MATLAB – Step by Step Exercise20. Write a comment5. %6. %own,thatThis is a commentRealize that from now the code is yourso you don't need to follow the same lineI write here.21. Calculate the average of the dates by dividingthe sum by the number of elementsaverage dates sum all/how may dates;22. Display in the command line a text, and later theaveragedisp('The average is: ');disp(average dates )

Introduction to MATLAB – Step by Step Exercise23. Plot the sin(dates)f x sin(dates);plot (dates, f x);24. Plot (dates)2 / (150000) – 0.02* (dates) 12:ff x (dates). 2/(150000) - 0.02*(dates) 12plot (dates, ff x);25. Use "hold on" between the two plots :ff x (dates). 2/(150000) - 0.02*(dates) 12;plot (dates, ff x);hold onf x sin(dates);plot (dates, f x);

Introduction to MATLAB – Step by Step Exercise26. Realize that we can transform numbers to string anduse it to display test inside a "disp" as a vectordisp(['Dois mais Dois igual a: ' num2str(4)]);27. Create a for to read each element of the vector anddisplay its valuefor i 1:how may datesdisp(['The date is: ' num2str(dates(i))]);end

Introduction to MATLAB – Step by Step Exercise28. Create a "if" to check if a year is before, equal orafter year 1800year 1750;if year 1800disp('Year is before 1800');elseif year 1800disp('Year is 1800');elsedisp('Year is above 1800');end

Introduction to MATLAB – Step by Step Exercise29. Incorporate and modify the "if" inside your "for", tocheck if a date is before, after or equal 1814for i 1:how may datesdisp(['The date is: ' num2str(dates(i))]);if dates(i) 1814disp('Before 1814');elseif dates(i) 1814disp('It is 1814!');elsedisp('After 1814');endend

Introduction to MATLAB – Step by Step Exercise29. Incorporate and modify the "if" inside your "for", tocheck if a date is before, after or equal 1814for i 1:how may datesdisp(['The date is: ' num2str(dates(i))]);if dates(i) 1814disp('Before 1814');elseif dates(i) 1814disp('It is 1814!');elsedisp('After 1814');endend

Introduction to MATLAB – Step by Step Exercise30. Adapt your code from 29 to solve the example fromlast week:Create a a code that checks if you can buy alcohol inNorway, the type of alcohol, if you can enter in a night club,and if you can teach your friend to drive: age 18 – None 18 age 20 – Alcohol below 22%, no clubbing norteach 20 age 21 Alcohol above 22%, but no clubbing norteaching 21 age 25 – Alcohol above 22% and clubbing, butno teaching age 25 – All allowed

Introduction to MATLAB – Step by Step Exercise31. Function: a named section of a program thatperforms a specific task. Realized that "sum", "length"and "times" is a functionsum([1 2])length([1 2])times([2],[2])

Introduction to MATLAB – Step by Step Exercise32. Study the basic command to create a function: function to add any two numbers:function tocreate a function!what thefunction returns!what thefunctionreceives!function [sum number] add numbers(x,y)!!"sum number x y;!name of the function!!end!variable that receivesthe operation!operation/taskperformed bythe function!

Introduction to MATLAB – Step by Step Exercise33. Based on 32, created a function that adds twonumbers called "add numbers".34. Use your "add numbers:add numbers(2,3)add numbers(10,32)35. Create a new function, that multiply 2 numbers,and use it36. Create a function that transform years in days

Introduction to MATLAB – Step by Step Exercise37. Create a function that check if a number is aboveor bellow 181438. Create a function that receives a vector anddisplay all the elements of this vector39. Create a function that calculates sigma for acantilever given your P, L and hfunction [sigma] tension(P,L,h)!"sigma P*L*6/(h 3);!end!

Introduction to MATLAB – Step by Step Exercise40. Create a function calculate the area (I) betweentwo points (a,b) by the trapezoidal rule:

Introduction to MATLAB – Step by Step Exercise41. Create matrices d, e and f by concatenatingvectors a, b and c: a [1 2]; b [3 4]; c [5;6]; d [a;b]; e [d c]; f [[e e];[a b a]];

Introduction to MATLAB – Step by Step Exercise42. Consider the a 2, b 4, c 6, d 9 and calculate2A in MATLAB given :43. Consider θ pi/6, m’ 4, n’ 2, calculate the valueof [m,n] for:

Introduction to MATLAB – Step by Step Exercise44. Solve the problem from 1st day, calculating howmuch sales the shop makes on each day in matrixoperations:Matrix multiplication example: Beef pies cost 3 each Chicken pies cost 4 each Vegetable pies cost 2 eachThey are sold in 4 daysthe value of sales for Monday is calculated as: Beef pie value Chicken pie value Vegetable pie value 3 13 4 8 2 6 83 ( 3, 4, 2) (13, 8, 6) 3 13 4 8 2 6 83

Introduction to MATLAB – Step by Step Exercise45. Create a multi-dimensional matrix based on thefigure below:

Introduction to MATLAB – Step by Step Exercise46. Obtain the following plot:t 0:0.1:10;y1 sin(t);y2 cos(t);plot(t,y1,'r',t,y2,'b--');x [1.7*pi;1.6*pi];y [-0.3; 0.7];s ['sin(t)';'cos(t)'];text(x, y, s);% Add comment at (x,y)title('Sin and Cos'); % Titlelegend('sin','cos') % Add legendxlabel('time')% the name of X-axisylabel('sin & cos') % the name of Y-axisgrid on% Add gridaxis square% set figure as a shapeof square

Introduction to MATLAB – Step by Step Exercise47. Obtain the similar curving fit data using polyfitand polyval:x [14.2, 16.4, 11.9, 15.2, 18.5, 22.1,19.4, 25.1, 23.4, 18.1, 22.6,17.2];y [215, 325, 185, 332, 406, 522, 412,614, 544, 421, 445, 408];coeff polyfit(x,y,1);y fit polyval(coeff,x);plot(x,y,'r ',x,y fit), grid on,xlabel('x-data'), ylabel('y-data'),title('Basic curve-fitting'),legend('Original data','Line ofbest fit','Location','SouthEast')

Introduction to MATLAB – Step by Step Exercise48. Obtain the following 3D plot:t 0:pi/50:10*pi;plot3(sin(t),cos(t),t, itle('3D helix')

Introduction to MATLAB – Step by Step Exercise49. Define a meshgrid and plot the following3D function:where a 3, c 0.5, -1 x 1 and -1 y 1x linspace(-1,1,50);y x;a 3c 0.5[xx, yy] meshgrid(x,y);z c*sin(2*pi*a*sqrt(xx. 2 yy. 2));surf(xx,yy,z), colorbar, xlabel('x'), ylabel('y'),zlabel('z'),title('f(x,y) c sin(2 \pi a \surd(x 2 y 2))')figure;mesh(xx,yy,z), colorbar, xlabel('x'), ylabel('y'),zlabel('z'), title('f(x,y) c sin(2 \pi a \surd(x 2 y 2))')

Introduction to MATLAB – Step by Step Exercise50 Plot the following 3D curves using the plot3 functiona)Spherical helixb)where c 5 and 0 t 10πSine wave on a spherewhere a 10, b 1, c 0.3, and 0 t 2π

Introduction to MATLAB – Step by Step Exercise51 Plot the following 3D curves using the surf functionSine surfacewhere 0 u 2π and 0 v 2πElliptic toruswhere r1 r2 0.5, t 1.5, 0 u 10π and 0 v 10π

Introduction to MATLAB – Step by Step Exercise52. Describe each part from the trapezoidalfunction from MATLAB

Introduction to MATLAB – Step by Step Exercise53. Remind about differential equations, andhow

Introduction to MATLAB – Step by Step Exercise54. Using the trapezoidal function plot and integrate(0-pi/2) for f(x) sen(x) and f(x) cos(x)x 0:pi/100:pi;y sin(x);trapz(y,x) % returns 1.9338plot (x,y,'k-*')%for the linesfor i 1:length(x)line([x(i) x(i)], [0 y(i)])end

Introduction to MATLAB – Step by Step Exercise55. Using the trapezoidal function plot and integratethe number of passengers

Introduction to MATLAB – Step by Step Exercise56. Plot the bell-shaped function f(x), x range [0,1],varying α in [1.5, 2, 4, 9 ]Using the trapezoidal function, calculate the areafrom the range x [0.2, 0.8] for all four αf(x) 4 α * x (α - 1) * (1 - x) (α - 1)

Introduction to MATLAB – Step by Step Exercise57. Plot the following solids in revolution (cylinder)function and calculate its volumea)b)A meshgrid(linspace(0, 2*pi, 50),linspace(0, 2*pi, 50)) ;X 3 .* cos(A);Y 3 .* sin(A);Z meshgrid(linspace(-5, 5, 50),linspace(-5, 5, 50))';surf(X, Y, Z), axis equalt 0:pi/10:2*pi;[X,Y,Z] cylinder(2 cos(t));surf(X,Y,Z)axis square

Introduction to MATLAB – Step by Step Exercise58. Design a group of cranes, varying square crosssection and load for L 3m. Check if cranecollapses (σmax 250MPa)hhσ PL*6/h3Consider:load vector 100:100:1000!section h vector 10:10:100!

Introduction to MATLAB – Step by Step Exercise59. Giving the cities represented by letters A to F, andthe distance among them represented by the value inthe connecting line, calculate the shortest order tovisit ALL the citiesTravel salesman problem solution: Acquire data from every city Calculate distance between all thecities (A-B, A-C, . E-F) Try every possible combination Answer is the combination withthe shortest sum

Introduction to MATLAB – Step by Step Exercise60. Sketch a problem of your own which you thinkthat MATLAB can help to solve

Introduction to MATLAB – Step by Step Exercise 32. Study the basic command to create a function: function to add any two numbers: function [sum_number] add_numbers(x,y)!! "sum_number x y;!! end! function to create a function! what the function returns! name of the function! what t

Related Documents:

INDEX PRESENTATION 5 THE THUMB 7 MECHANICAL EXERCISES 8 SECTION 1 THUMB Exercise 1 12 Exercise 2 13 Exercise 3 - 4 14 Exercise 5 15 Estudio 1 16 SECTION 2 THUMB WITH JUMPS Exercise 6 17 Exercise 7 - 8 18 Exercise 9 19 Exercise 10 20 Exercise 11 - 12 21 Estudio 6 22 SECTION 3 GOLPE Exercise 13 23 Exercise 14 24 Exercise 15 25 Exercise 16 - 17 26 Exercise 18 27 .

Chapter 1 Exercise Solutions Exercise 1.1 Exercise 1.2 Exercise 1.3 Exercise 1.4 Exercise 1.5 Exercise 1.6 Exercise 1.7 Exercise 1.8 Exercise 1.9 Exercise 1.10 Exercise 1.11 Exercise 1.12 Fawwaz T. Ulaby and Umberto Ravaioli, Fundamentals of Applied Electromagnetics c 2019 Prentice Hall

CLIMATE-SMART AGRICULTURE TRAINING MANUAL iv Exercises Exercise A.1 Introduction to the training course 18 Exercise A.2 Weather and climate 18 Exercise A.3 Global Warming 18 Exercise A.4 Changes in rainfall 18 Exercise A.5 The greenhouse effect 19 Exercise A.6 Climate change in your area 19 Exercise B.1 Understanding the effects of future climate change 43

TRX Power Stretch. Round 4, Exercise 1 Round 4, Exercise 2 Round 4, Exercise 3 Round 4, Exercise 4 Round 4, Exercise 5 Round 4, Exercise 6. Block 5 – Hamstring/Folds (Adjustment: mid length) EXERCISE SETS REPS / TIME SET REST TRAN

2. Selecting an exercise 4 2.1 Scoping the exercise 4 2.2 Setting the aims and objectives 4 2.3 Types of exercise 5 2.4 Choosing the type of exercise 6 2.4.1 What is being tested? 6 2.4.2 What resources are available? 7 3. Planning the exercise 9 3.1 Exercise management team 9 3.2 Exercise plan 9 3.3 Target audience 10

EXERCISE 17 Spinal Cord Structure and Function 277 EXERCISE 18 Spinal Nerves 287 EXERCISE 19 Somatic Reflexes 299 EXERCISE 20 Brain Structure and Function 309 EXERCISE 21 Cranial Nerves 333 EXERCISE 22 Autonomic Nervous System Structure and Function APPENDIX C: 343 EXERCISE 23 General Senses 355 E

Exercise 9, Joints. 7 11/1 11/3 .Exercise 10, Muscles of body Exercise 10, continue. 8 11/8 11/10 Cat Dissection. Exercise 11, Spinal cord. 9 11/15 11/17 Exercise 11, Spinal Nerves and Reflexes. Exercise 12 Brain. 10 11/22 Exercise 12 Cranial Nerves And Sheep Brain. Thanks Giving Break, Nov 24 – Nov 27. 11 11/29 12/01

Be able to instruct gym-based exercise 4. Be able to supervise clients undertaking gym-based exercise 5. Be able to bring a gym-based exercise session to an end 6. Be able to reflect on providing gym-based exercise 7. Be able to support clients taking part in gym-based exercise 8. Understand how to provide gym-based exercise UV20527 3 1 .