ENGR 121, Lab notes, Week 1
ENGR 121, Lab notes, Week 1 ENGR 121-B
Popular in Computation Lab I
Popular in Engineering and Tech
This 3 page Class Notes was uploaded by spencer.kociba on Wednesday September 21, 2016. The Class Notes belongs to ENGR 121-B at Drexel University taught by in Fall 2016. Since its upload, it has received 42 views. For similar materials see Computation Lab I in Engineering and Tech at Drexel University.
Reviews for ENGR 121, Lab notes, Week 1
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/21/16
ENGR 121 B Lab Notes for 9/21/2016 Spencer Kociba Summary of lab: MATLAB Tutorial, basic vocabulary and hands on work with the program *This set of notes is very much like a beginner's glossary or can be used as a reference to basic commands in MATLAB ***Note: Important phrases, commands and concepts are in bold ● Uppercase vs lowercase matters ● Default variable is “ans” and will change if you do not assign a fixed variable to your outcome ● multiplication= * ● division= / ● Variable = assignment <<this is the format for assigning variables ● Clear (variable name) = remove variable from workspace ● MATRICES ○ >>C=[1,2,3,4,5] <<commas can also be spaces ○ >>size(C) ○ ans= 1 5 ○ Size = shows row by columns size of the matrix named ● Use a semicolon to suppress output in the command window (keeps space uncluttered) ○ Ex. >>mynum=6; ○ >>mynum+34; ○ >>y=mynum/2 ○ >> ans = ○ >> y=20 ● who= shows all names of all variables in your workspace ● clc= clear all of command window (variables remain in workspace) ● Clear all = deletes all variable assignments ● New Script Button: pulls up editor that you can edit, delete, run and save written codes/programs (great for testing programs to get a certain answer aka the quizzes coming up in later weeks) ○ Ex. 1 x=10; ○ 2 y=5; ○ 3 z=x+y ○ “RUN” ○ ans= ○ z=15 ● % in front of a command (in editor)= suspends actions in the program (if running multiple times ○ Ex. 1 %clear all ○ 2 clc ○ 3 x= x+4; ○ 4 y=5; ○ 5 z=x+y ■ z= (this value would increase every time you run the program) ■ If you remove the % in front and the (x+4) the program will run as normal ● ( *number) ^ (power) *? ○ Is: (value) (number)❑ ∗(value∗π) ○ Is NOT: (number)❑ ● theta=_______ : assigned angle ○ Default is radians ● (trig func)d (____) = trig func results in degrees ● help(command name): detailed explanation of how the command works, different uses for command, and differrent notations of the command in MATLAB ● exp(value): e❑ (value) ○ 5^2 = 25 ○ (5)^2= 25 ● fix()= rounds towards zero of nearest ○ Negatives #s round up ○ Positives #s round down ● round(X,N) = round to the Nth digit to the right of the decimal ● ceil(X) = round to the nearest integer towards infinity ● floor(X) = round to nearest integer towards negative infinity ● std= standard deviation (usually combined with randn(__)) ● = is used as the assignment operator ● == is used in a logical operation like “is the left equal to the right side in this equation (will result in logical output of 0 or 1) ● PLOTTING ○ Creating plots/graphs in MATLAB requires a few steps ■ >>x= (number you want the x axis to start on): (increment):(number to end with); ■ >>Figure; ■ >>plot(variable or expression/equation); ■ >>y=(number you want at the top of the figure): (increment):(number you want at the bottom of the figure) ○ A graph will appear on your screen, with the x and y axis labeled by the increments and in the range that you indicated ● RANDOM NUMBERS ○ rand(a)= a x a matrix of random numbers in the range (0,1) ■ (all possible numbers between but not including 0 and 1) ■ ○ rand(a,b)= a x b matrix of random numbers in the range (0,1) ■ Addition or subtraction operations will change the starting number of the range ● Ex. 5 + rand(a) has a range of (5,6) ■ Multiplication or division will change the width of the range ● Ex. 5*rand(a) has a range of (0,5) ○ randi(a,b)= b x b matrix of integers in the range (0, a) ■ (all possible integers between AND including 0 and a) ■ ○ randi([a,b],c,d)= range of (a,b) and matrix of c x d ○ randn() =bell curve of random deviations ■ Ex. 1+ 2*randn(100,1) ■ Mean= 1, StD= 2, Data generated in a 100 x 1 matrix ● LOGICAL TESTING ○ Outputs ■ 1=true ■ 0=false ○ > = is ≥ ○ < = is ≤ ○ ~ = is ≠ ○ && is “u and v” ○ || is “u or v” ■ Need to use && or || when doing several inequalities in a row like or MATLAB will use order of operations ● Ex. >> 10>5>2 ● >>(logical:1)>2 ● >>logical: 0 ● Instead input: >> 10>5&&5>2
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'