### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# SYST 221 SYST 221

Mason

### View Full Document

## 22

## 0

## Popular in SYSTEMS MODELING LABORATORY

## Popular in Computer Science and Engineering

This 67 page Bundle was uploaded by Albaraa Kayal on Saturday March 5, 2016. The Bundle belongs to SYST 221 at George Mason University taught by Dr. Zaidi in Spring 2016. Since its upload, it has received 22 views. For similar materials see SYSTEMS MODELING LABORATORY in Computer Science and Engineering at George Mason University.

## Reviews for SYST 221

### 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: 03/05/16

Table of Contents ........................................................................................................................................ 1 Problem 1 .......................................................................................................................... 1 Problem 2 .......................................................................................................................... 1 Problem 3 .......................................................................................................................... 2 Problem 4 .......................................................................................................................... 3 Problem 5 .......................................................................................................................... 3 Problem 6 .......................................................................................................................... 5 Problem 7 .......................................................................................................................... 6 Part (1) .............................................................................................................................. 6 Part (2) .............................................................................................................................. 8 Part (3) .............................................................................................................................. 8 Part (4) .............................................................................................................................. 9 Problem 8 ........................................................................................................................ 10 Problem 9 ........................................................................................................................ 11 Problem 9 (Extra Code) ...................................................................................................... 12 % Systems 221 - Spring 2016 % Solution to Problem Set Week 2 Problem 1 A = [2 -1 4; 4 1 -8; 2 1 2]; B = [4 -1 -2; 2 1 1; 4 1 -4]; C = A.*B % Note the (.) before the multiplication (*) operator. C = 8 1 -8 8 1 -8 8 1 -8 Problem 2 clear A = [2 -1 3; 4 1 8; 2 1 4]; I = eye(3); B = I/A; % The B matrix can also be constructed by running B = inv(A) LHS = A*B LHS = 1 0 0 0 1 0 1 0 0 1 Problem 3 Special attention should be given to the order of the variables in each equation. First rearrange the terms to have the equations look like: 4x + 6y - 2z = 8 2x + 8y + 2z = 4 6x + 3y + 10z = 10 % Part (1) % The matrix representation CX = D can now be constructed with % the matrices: C = [4 6 -2; 2 8 2; 6 3 10]; D = [8;4;10]; % note that D is a column vector X_i = C\D % note the left division % Part (2) % The matrix representation XE = F can now be constructed with % the matrices: E = C'; % E is the transpose of C F = D'; % F is the transpose of D, thus a row vector X_ii = F/E % note the right division. You may also check the identity (C\D)’ = (C’\D’) % Note the difference between X_i and X_ii. Once is a row vector and other % is a column vector. % Part (3) syms x y z [solx, soly, solz] = solve(4*x + 6*y - 2*z == 8, 2*x + 8*y + 2*z == 4,... 6*x + 3*y + 10*z == 10, x, y, z); % Note there is no need to rearrange % terms while solving this way. solution = [solx;soly;solz] solution = eval(solution) X_i = 1.8313 0.0723 -0.1205 X_ii = 1.8313 0.0723 -0.1205 solution = 2 152/83 6/83 -10/83 solution = 1.8313 0.0723 -0.1205 Problem 4 fprintf('\n\nProblem 4\n\n') % creating vector X: X=1:2:15; % writing the provided equation. Note the element-wise operations. y = (X.^(1/3) + 5*X)./(4*X.^2 - 10); % creating a 2x8 matrix in which the first row has the values for X (the % row vector provided), and the second row has the calculated values for % each x. You might want to suppress the semi-colon at the end of the % equation so MATLAB will show you the xytable xytable=[X;y]; % Now we use the xytable as input to the fprintf command. Note that the % text includes two placeholders (%-f and %+f) and the fprintf command will % substitute each column in xytable at the placeholders. The result will be % eight "runs" of the fprintf command, one for each column in xytable. % Please, also note the syntax of the placeholders, which convey the % commands needed to display the sign of the computed values. fprintf('When the x-value is %-f, then the y-value is %+f\n',xytable) Problem 4 When the x-value is 1.000000, then the y-value is -1.000000 When the x-value is 3.000000, then the y-value is +0.632394 When the x-value is 5.000000, then the y-value is +0.296778 When the x-value is 7.000000, then the y-value is +0.198457 When the x-value is 9.000000, then the y-value is +0.149937 When the x-value is 11.000000, then the y-value is +0.120726 When the x-value is 13.000000, then the y-value is +0.101128 When the x-value is 15.000000, then the y-value is +0.087041 Problem 5 fprintf('\n\nProblem 5\n\n') 3 % This is simply to exercise your understanding of the fplot command. Note % that it is capable of parsing the equation and using it to build the plot % in the interval provided. % The figure(1) command is used to tell Matlab that this is, well, figure 1. % This is usefull when you want to plot more than one figures and don't % want the newest figure to overwrite the previous one. figure(1) fplot('0.01*x^5 - 0.03*x^4 + 0.4*x^3 - 2*x^2 - 6*x + 5',[-4,6]) % I'm adding the commands below as an extra, just to show you that they % work in any graph, no matter whether you built it using fplot or plot legend('f(x)',2) xlabel('Value of x') ylabel('f(x)') Problem 5 4 Problem 6 fprintf('\n\nProblem 6\n\n') % First, let's make a very long row vector that we will use to store the % values of the independent variable x. That is, we will apply the function fx to each element of the row % vector. Since it has a very tiny space between its elements, the final % result is an apparently smooth line. x=[-2:0.01:4]; % Now, let's write the provided function: fx=3*x.^3 - 25*x + 10; % Pay special attention to the syntax of the plot command. This will create % a line for fx built from various blue dashes. % Note that we use the figure(2) command to tell MATLAB we want a new % window, so the previous one will not be overwritten. figure(2) plot(x,fx,'linestyle','-','color','blue') % Next, we calculate the derivative: % The calcuated first derivative 9*x^2 - 25 dfx = 9*x.^2 - 25; % Note again the syntax. The line command is basically equivalent to the % plot command, but uses the latest graph instead of creating a new one. line(x,dfx,'linestyle','--','color','red') % gtext is a cool interactive command. In run time MATLAB will show you a % crosshairs and wait for you to point where the text in each gtext should % be placed gtext('f(x)') gtext('f''(x)') % after the gtext commands, MATLAB will resume the script and execute the % commands below legend('f(x)','f''(x)',0) xlabel('Value of x') ylabel('f(x) and f''(x)') Problem 6 5 Problem 7 clear Part (1) t = 0:1:10; % creates a row vector for time in seconds from 0 to 10 % formula for distance: x = 0.4*t.^3 - 2*t.^2 - 5*t + 13; % note the element-wise operations % formula for velocity: v = 1.2*t.^2 - 4*t - 5; figure(1) plot(t,x,'color','blue') % ploting distance in blue figure(2) plot(t,v,'color','magenta') % ploting velocity in green 6 7 Part (2) figure(3) subplot(2,1,1), plot(t,x,'color','blue') % colors are not required in the problem subplot(2,1,2), plot(t,v,'color','magenta') Part (3) figure(3); % note that I'm superimposing the labels to the previous figure % Thus, you must run the code above to get the correct picture subplot(2,1,1) xlabel('\fontsize{14}Time (seconds)') ylabel('\fontsize{14}\color{blue}Position (x)') subplot(2,1,2) xlabel('\fontsize{14}Time (seconds)') ylabel('\fontsize{14}\color{magenta}Velocity (v)') 8 Part (4) figure(3) % note that I'm superimposing the titles to the previous figure subplot(2,1,1) title('\bf\fontsize{14}\color{blue}Position x(t)') text(3,10,'\color{blue}x(t) = 0.4t^3 - 2t^2 - 5t + 13') % this was not required in the problem subplot(2,1,2) title('\bf{Velocity \itv(t)}','FontSize',14, 'color', 'magenta') % compare with the title above text(3,10,'\color{magenta}v(t) 1.2t^2 - 4t - 5') % this was not required in the problem clc 9 Problem 8 Substituting the four points in the function gives us four equations: For point (-2, 3): -8a + 4b - 2c + d = 3 For point (-1, 2): -1a + b - c + d = 2 For point (0, 3): d = 3 For point (1, 6): a + b + c + d = 6 This system of linear equations can be represented in the matrix for AX = Y or we can solve the system of equations using solve function. % The following is the solution using solve function: syms a b c d [sola, solb, solc, sold] = solve(-8*a + 4*b - 2*c + d == 3, ... -a + b - c + d == 2, d == 3, a + b + c + d == 6, a, b, c, d); fprintf('\n Problem 8 Solutions') fprintf('\n--------------------------\n') fprintf('The value of a is '), disp(sola) fprintf('The value of b is '), disp(solb) fprintf('The value of c is '), disp(solc) fprintf('The value of d is '), disp(sold) Problem 8 Solutions -------------------------- The value of a is 0 The value of b is 1 10 The value of c is 2 The value of d is 3 Problem 9 clear % I always like to clear variables to avoid any problems. % Defining the known parameters: P0 = 50; % Initial population in millions t = 20; % Time for the population to duplicate P20 = 100; % In 20 years the popution is doubled r = (log(P20/P0))/t fprintf('The yearly rate of growth is: %+f\n', r) % Creating the vector t with the time values: t = [5 10, 15, 20]; % You may also create the vector t using the input function. % User will enter the years during runtime. % t(1) = input('Enter the first interval in years: '); % t(2) = input('Enter the second interval in years: '); % t(3) = input('Enter the third interval in years: '); % Defining the formula for population: P = P0 * exp(r*t) % Creating a vector with the years and respective populations % This is to facilitate our use of fprintf to save the file results = [t ; P] % Feedback to the user. Not required in the problem: disp('Your result vector is:') disp(results) r = 0.0347 The yearly rate of growth is: +0.034657 P = 59.4604 70.7107 84.0896 100.0000 11 results = 5.0000 10.0000 15.0000 20.0000 59.4604 70.7107 84.0896 100.0000 Your result vector is: 5.0000 10.0000 15.0000 20.0000 59.4604 70.7107 84.0896 100.0000 Problem 9 (Extra Code) The following code will allow you to store the results in an external file Opening the file: f1 = fopen('W2_Output.txt','w') % Inserting the results within the file: fprintf(f1,'Results of Homework 2, Problem 2') fprintf(f1,'\n--------------------------------') fprintf(f1,'\n Years Population ') fprintf(f1,'\n (millions) ') fprintf(f1,'\n %2.f %2.2f', results) % Closing and saving the file: fclose(f1) % Although not required in the problem statement, it is always % a good to provide some feedback to the user: disp('File W2_Output.txt successfully saved!') f1 = 3 ans = 32 ans = 33 ans = 31 ans = 31 12 ans = 105 ans = 0 File W2_Output.txt successfully saved! Published with MATLAB® R2015a 13 W1 SYST 221: Systems Modeling Laboratory Problem Set - Submission via Blackboard by Monday, Feb 01, 1:30 pm. - Submit a text file with solutions. - Use the file name convention: LastNameFirstName_W1 - Problems in blue are for classroom practice. Problem 1 A trigonometric identity is given by: Verify that the identity by calculating each side of the equation for Problem 2 (2 points) A trigonometric identity is given by: Verify that the identity calculating each side of the equation for Problem 3 a) Using MATLAB, calculate Problem 4 (3 points) Calculate the surface area of a sphere with volume 320 m . Problem 5 (a) Create a column vector with elements 3, 6, 7, 76, 546, and 910. (b)Create a row vector with 15 equally spaced elements in which the first element is -1 and the last element is -25. (c) Using the ones and zeros commands, create a 2 x 10 matrix in which the first five columns are 0s and the next five columns are 1s. (d)Using the ones and zeros commands, create a 5 x 5 matrix in which the first two rows are 1s and the next three rows are 0s. Problem 6 (2 points) Create a 5 x 5 matrix that has: The first two elements of the first three rows are fives. The last two elements of the last three columns are twos. The rest of the elements can be zeros. Problem 7 (3 points) Create a 5 x 7 matrix that has: Elements from 1 to 35 in sequence. That is, first row should be 1 2 3 … 7, the last row should be 29 30 … 35. Save the result in variable mat_prob7 Extract a 3 x 3 matrix from mat_prob7 matrix. The top leftmost element should be 16. Save it in a different variable. SYST 221: Systems Modeling Laboratory Problem Set - Use the file name convention: LastNameFirstName_W3 - Problems in blue are for classroom practice. Problem 1 (a) Evaluate the polynomial ????(????) = 3???? + 2???? + 1 at x = 5, 7, and 9. (b)Calculate the roots of the polynomial p(x) Problem 2 (3 points) 5 4 3 2 For the polynomial f (x) = 0.025x – 0.0625x – 0.333x + x – 2 (a) Calculate the value of the function for x = –1, – 0.5, 0, 0.5, 1, 1.5, 2, 2.5 (b) Plot the polynomial for − 4 ≤ x ≤ 4 (c) Find f(9) (d) Find the value(s) of x for which f(x) = 0 Problem 3 (a) Plot the power function ???? = 2???? −0.5on rectilinear axes. (b) Plot the function in (a) on suitable axes to view the graph of function as a straight line. (c) Plot the exponential function ???? = 10(10)−???? on rectilinear axis (d) Plot the function in (c) using suitable axes to view the graph of function as a straight line. Problem 4 (3 points) The following data points are taken from a process believed to follow a power function. v (mi/h) 20 30 40 50 60 70 d (ft) 45 80 130 185 250 330 (a) Find a quadratic (e.g, x +…) polynomial that fits the data. (b) Plot the data points against the function in “a” above. Problem 5 (4 points) (a) On a single figure window, plot the function ???? = 10???? for m = -2, -1, 0, 1, 2 (use rectilinear axes unless specified otherwise). (b)For what values of m does the function pass through the origin? (c) On a single figure window, plot the function ???? = ???? for m = -0.5, -0, 0.5, 1, 2
(use rectilinear axes unless specified otherwise). (d)For what values of m does the function pass through the origin? SYST221:S YSTEMS M ODELING L ABORATORY CALCULUS IMATLAB I. Calculating Limits (1) limit The limit command belongs to MATLAB symbolic computing feature; you need to use the syms command to tell MATLAB which symbolic variables you are using. Example:
lim????→0(???? + 5)/(???? + 7) syms x limit((x^3 + 5)/(x^4 + 7)) % limit(x^2 + 5, 3)for % limit(x^2 + 5) when x approaches 3 You can also compute limit of a function, as the variable tends to some number other than zero. To calculatelim????(????), we use the limit command with arguments. The first being the expression and the ????→???? second is the number, that x approaches, here it is a. Use inf for ∞. syms x f = (3*x + 5)/(x-3); g = x^2 + 1; l1 = limit(f, 4) l2 = limit (g, 4) lAdd = limit(f + g, 4) lSub = limit(f - g, 4) lMult = limit(f*g, 4) lDiv = limit (f/g, 4) II. Calculating Derivatives (2) diff In its simplest form, the function you want to differentiate is passed to diff command as an argument. 2 -2 For example, let us compute the derivative of the function f(t) = 3t + 2t Week 4 Page 1 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com syms t f = 3*t^2 + 2*t^(-2); diff(f) syms x %More Examples syms t f = (t^2 + 3)*(sqrt(t) + t^3) der2 = diff(f) f = (x^2 - 2*x + 1)*(3*x^3 - 5*x^2 + 2) der3 = diff(f) f = (2*x^2 + 3*x)/(x^3 + 1) der4 = diff(f) f = (x^2 + 1)^17 der5 = diff(f) f = (t^3 + 3* t^2 + 5*t -9)^(-6) der6 = diff(f) (3) diff(f, n) Let us compute the second derivative of the function y = f(x) = x .e f = x*exp(-3*x); diff(f, 2) Calculating the Minima and Maxima of a Function The highest or lowest points on the graph of the function at a particular locality are called local maxima or local minima of the graph. For a function y = f(x) the points on the graph where the graph has zero slope are called stationary or fixed points. In other words stationary points are where f'(x) = 0. The following steps allow us to find the stationary points of a function: Step 1: Differentiate the function Step 2: Set the derivative to zero Step 3: Solve the equation in Step 2 Week 4 Page 2 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com Example: Find the minimum and maximum value of the following function in the interval [-4 4] using stationary points. 3 2 f(x) = 2x + 3x − 12x + 17 % Plot the graph syms x y = 2*x^3 + 3*x^2 - 12*x + 17; % defining the function ezplot(y) % Zoom-in on the observed local maxima and minima % ezplot(y, [-2, 2]) % Compute the derivative g = diff(y) % Equate g = 0 and solve for x. This can be done by calculating the roots of % g or by using the solve command % or by using the roots: s = roots([6 6 -12]). Both result in s = 1, -2 s = solve(g) % Calculate the value of the function at these points. These are minimum and maximum values of the function. ymin = subs(y, 1) ymax = subs(y, -2) III. Calculating Integrals (4) int(s) %finds the indefinite integral of a symbolic expression s with respect to its symbolic variable (or variable closest to x) (5) int(s, t) %finds the indefinite integral of a symbolic expression s with respect to t (6) int(s, a, b) %finds the definite integral of a symbolic expression s from a to b with respect to its symbolic variable (or variable closest to x) (7) int(s, t, a, b) %finds the definite integral of a symbolic expression s from a to b with respect to t Week 4 Page 3 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com % Examples of integration using MATLAB syms x x1 alpha u; int(1/(1+x^2)) int(sin(alpha*u),alpha) int(x1*log(1+x1),x1, 0,1) int(asin(sin(x)),x,0,5) %does not find an integral Week 4 Page 4 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com IV. Solving Differential Equations (4) dsolve (‘eqn’) eqn is a text string used to enter the equation. It returns a symbolic solution with a set of arbitrary constants that MATLAB labels C1, C2, and so on. For example, ????′(????) = −2 ∗ ???? + ????????????(????) is entered as 'Df = -2*f + cos(t)' ????"(????) + 2????′(????) = 5????????????3???? should be entered as 'D2y + 2*Dy = 5*sin(3*x)' % Simple example of a first order differential equation: % dy/dx = 5y. ODE1 = 'Dy = 5*y' ODE1sol = dsolve(ODE1) % You may alsouse: ODE1sol = dsolve(ODE1, ‘x’) % We can also specify the initial condition as follows: initCond = ‘y(0) = 2’ ODE1sol = dsolve(ODE1, initCond, ‘x’) % Another example of a second order differential equation as: % y" - y = 0, y(0) = -1, y'(0) = 2. sol = dsolve('D2y - y = 0','y(0) = -1','Dy(0) = 2') t = -10:.01:10; y_values = eval(vectorize(sol)); plot(t, y_values) % You may solve the systems of ODEs in a similar manner. sysODE1 = 'Dx = 2*x + 3*z' sysODE2 = 'Dy = 6*z - y' sysODE3 = 'Dz = 3*y - 12*x' initConds = 'x(1) = 5, y(2) = 3, z(9) = 0' [x,y,z] = dsolve(sysODE1,sysODE2, sysODE3, initConds) Week 4 Page 5 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com V. The Laplace Transform The Laplace transform provides a systematic and general method for solving linear ODEs, and is especially useful either for nonhomogeneous equations whose right-hand side is a function of time or for sets of equations. Another advantage is that the transform converts linear differential equations into algebraic relations that can be handled easily. Laplace transform is denoted as transform of f(t) to F(s). (5) laplace(f(t)) Examples: syms s t a b w laplace(a) laplace(t^2) laplace(t^9) laplace(exp(-b*t)) laplace(sin(w*t)) laplace(cos(w*t)) (6) ilaplace(F(s)) Examples: syms s t a b w ilaplace(1/s^7) ilaplace(2/(w+s)) ilaplace(s/(s^2+4)) ilaplace(exp(-b*t)) ilaplace(w/(s^2 + w^2)) ilaplace(s/(s^2 + w^2)) (7) pretty(f) (8) simplify(f) VI. Partial Fraction Expansion Let X(s) denote the transform. The expansion coefficients are called the residues and the factors of the denominator of X(s) are called the poles. The poles include the characteristic roots of the model and any denominator roots introduced by the input function. If the order m of the numerator of X(s) is greater than the order n of the denominator, the transform can be represented by a polynomial K(s), called the direct term, plus a ratio of two polynomials where the denominator degree is greater than the numerator degree. (9) [r, p, K] = residue(num, den) r contains the residues p contains poles K contains coefficients of the direct term K(s) in the polynomial form Week 4 Page 6 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com Examples: (a) >> [r, p, K]= residue([6, 57, 120, 80],[1, 9, 14]) r = 5 4 p = -7 -2 K = 6 3 which corresponds to (b) >> [r, p, K]= residue([5],[3, 12, 0, 0]) r = 0.1042 -0.1042 0.4167 p = -4 0 0 K = [] Week 4 Page 7 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com VII. Examples 1. Obtain the Laplace transform of the following: x(t) t -2t -3t x(t) 2-ae be x(t)10cos(2t) 2. Use MATLAB for the steps in the following solution of an ODE: Solution Steps: ???? Step 1: ????’’ + ???? = ???? ,????(0) = ????’(0) = 0 Step 2: Take Laplace transform (???? + 1) ????(????) = 1/(???? – 1) Step 3: Solve the resulting equation for Y(s) ????(????) = ( )(???? – 1) + (− )????(???? + 1) + (− )(???? + 1) 2 2 2 2 Step 4: Use inverse Laplace transform to get y(t) 1 1 1 ????(????) = ( )???? + (− )cos(????) + (− )sin(????) 2 2 2 % Step (1): We need to input our differential equation. % To simplify the commands, we'll start off by assigning our differential % equation to a variable: syms y t s Y2 ode = 'D(D(y))(t) + y(t) = exp(t)' % Note the notation for second derivative % use this instead of D2y. % Step (2): Now take the Laplace transform. Again, for convenience, % we assign the result to a new variable: LTode=laplace(ode,t,s) % Substituting initial conditions. This replaces laplace(y(t), t, s) with % a variable Y2, y(0) and D(y) (0) with the initial condition values. LTode=subs(LTode,{'laplace(y(t),t,s)','y(0)','D(y)(0)'}, {Y2, 0, 0}) % Step (3): Solving LTode for Y2 Y2 = solve(LTode, Y2) % Step (4): Applying inverse laplace to get bact to y(t) from Y(s) y2=ilaplace(Y2,s,t) Example from: http://www.math.ucsd.edu/~math20d/Fall/LabA4/LabA4.html Week 4 Page 8 of 8 Adapted and modified from Amos Gilat, Dr. Costa, Dr. Palm III, and tutorials on MathWorks and Tutorialspoint.com Table of Contents ........................................................................................................................................ 1 Problem 1 .......................................................................................................................... 1 Problem 2 .......................................................................................................................... 1 Problem 3 .......................................................................................................................... 1 Problem 4 .......................................................................................................................... 2 Problem 5 .......................................................................................................................... 2 Problem 6 .......................................................................................................................... 3 Problem 7 .......................................................................................................................... 4 % Systems 221 - Spring 2016 % Solution to Problem Set Week 1 Problem 1 u = pi/4; lhs = (cos(u))^2 rhs = (1 + cos(2*u))/2 lhs = 0.5000 rhs = 0.5000 Problem 2 u = 3*pi/4; lhs = (tan (u))^2 rhs = (1-cos(2*u))/(1+cos(2*u)) lhs = 1.0000 rhs = 1.0000 Problem 3 result = (((3^(-6))*log10(80))/((7^5) + 654)) + 910^(1/3) 1 result = 9.6905 Problem 4 The surface area is give by 4 * pi * r^2. Since we do not have 'r', we will calculate it first. The volume of a sphere is equal to (4 * pi * r^3)/3. We use this formula to calculate r and then use the formula for surface area to get the answer. volume = 320; r = nthroot((3 * volume)/(4 * pi), 3) % We can also calculate it by ((3 * volume)/(4 * pi))^(1/3) surface_are = 4*pi*(r^2) r = 4.2431 surface_are = 226.2477 Problem 5 %(a) [3; 6; 7; 76; 546; 910] %we can also calculate it by: [3, 6, 7, 76, 546, 910]' %(b) linspace(-1, -25, 15) %(c) A = zeros(2,5); B = ones(2, 5); C = [A B] %(d) E = ones(2,5); F = zeros(3,5); G = [E;F] ans = 3 6 2 7 76 546 910 ans = 3 6 7 76 546 910 ans = Columns 1 through 7 -1.0000 -2.7143 -4.4286 -6.1429 -7.8571 -9.5714 -11.2857 Columns 8 through 14 -13.0000 -14.7143 -16.4286 -18.1429 -19.8571 -21.5714 -23.2857 Column 15 -25.0000 C = 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 G = 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Problem 6 A = 5*ones(3,2); B = 2*ones(2,3); C = zeros(5,5); C(1:3, 1:2) = A; C(4:5, 3:5) = B 3 C = 5 5 0 0 0 5 5 0 0 0 5 5 0 0 0 0 0 2 2 2 0 0 2 2 2 Problem 7 mat_prob7 = [1:7; 8:14; 15:21; 22:28; 29:35] mat_prob7n = mat_prob7(3:5, 2:4) mat_prob7 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 mat_prob7n = 16 17 18 23 24 25 30 31 32 Published with MATLAB® R2014a 4 W4 SYST 221: Systems Modeling Laboratory Problem Set - Use the file name convention: LastNameFirstName_W4 - Problems in blue are for classroom practice. Problem 1 Solve the following differential equations: dy 2y 12 y(0) 10 (i) dt d y dy (ii) 2 3 2y 24 y(0) 10 y'(0) 0 dt dt 2 d y 2dy 5y 20 y(0) 0 y'(0) 10 (iii) dt2 dt Problem 2 (3 points) Solve the following differential equations where the input is f(t) = 5t and the initial conditions are zero. Plot the response of the following models for 0 ≤ t ≤ 1.5 (i) (ii) (iii) Problem 3 Obtain the Laplace transform of the following function: x(t) t -2t -3t x(t) 2-ae be x(t) 10cos(2t) Problem 4 (2 points) Calculate the Laplace transform of the following function: 2t 2t v(t) 3e sin5t 4e cos5t Problem 5 Calculate the inverse transform of the following functions: 100(s 3) F(s) 2 (i) (s 1)(s 2)(s 2s 5) 10 48 Y(s) 2 (ii) s2 (s2)(s 16) (iii) Expand the following transform using Partial-Fraction expansion. Also calculate the inverse transform. Problem 6 (2 points) Obtain the inverse Laplace transform x(t) for each of the following transforms: (i) (ii) Problem 7 (3 points) Solve the following problems: (i) (ii) 5 Table of Contents ........................................................................................................................................ 1 Problem 1 .......................................................................................................................... 1 Problem 2 .......................................................................................................................... 1 Part (d): The roots are the values of x for which f(x)= 0 ............................................................ 4 Problem 3 .......................................................................................................................... 4 Part (c) .............................................................................................................................. 6 Problem 4 .......................................................................................................................... 8 Problem 5 .......................................................................................................................... 9 % Systems 221 - Spring 2016 % Solution to Problem Set No. 3 clear all clc Problem 1 Part (a): The polynomial x^3 + 2*x^2 + 1 is represented in MATLAB® software as p = [3 2 0 1]; % Part (a) x = [5, 7, 9]; polyval(p, x) %Part (b): The roots of this polynomial are returned in a column vector by r = roots(p) ans = 426 1128 2350 r = -1.0000 + 0.0000i 0.1667 + 0.5528i 0.1667 - 0.5528i Problem 2 Part (a): The polynomial f (x) = 0.025x^5 – 0.0625x^4 – 0.333x^3 + x^2 – 2 is represented in MATLAB® as 1 clear f = [0.025 -0.0625 -0.333 1 0 -2]; % Part (a) x = [-1, -0.5, 0, 0.5, 1, 1.5, 2, 2.]; Fx = polyval(f, x); % Part (b): There are many ways of doing it depending on what you % want to have as the output. Here are some of those outputs: % (1) Not so good looking: figure (1) plot(x,Fx) xlim([-4 4]) % setting the limit of axis x to the interval of the function title('Problem 2 - Part (b) - First Approach') % (2) A little more refined: x2 = -4:0.01:4; % creating a discretized version of the interval [-4, 4] Fx2 = polyval(f, x2); % applying the polyval function to each point of the discretized interval above figure(2) plot(x2,Fx2) title('Problem 2 - Part (b) - Second Approach') % (3) We can always let MATLAB do it for us with fplot figure(3) fplot('0.025*x^5-0.0625*x^4-0.333*x^3+x^2-2', [-4, 4]) title('Problem 2 - Part (b) - Third Approach (fplot)') % Part (c) F9 = polyval(f, 9) F9 = 902.4055 2 3 Part (d): The roots are the values of x for which f(x)= 0 solu = roots(f); % There are three real roots. The following will extract the real % roots from solu rsolu = solu(imag(solu)==0) % Save only the real roots % You may now check if the value of the function is zero at thsoe points: rsolu = -3.6662 3.5880 -1.2549 Problem 3 Part (a) 4 x = [0 10]; figure(4) fplot('2*x^(-0.5)', x) title('f(x) = 2*x^ (-0.5)') xlabel('rectilinear scale') ylabel('rectilinear scale') % Part (b) figure(5) x = 0:0.01:10; y = 2*x.^(-0.5); % Note the .^ operator loglog(x , y) % This creates a log-log scale plot title('f(x) = 2*x.^ (-0.5)') xlabel('log scale') ylabel('log scale') 5 Part (c) figure(6) x = [0 10]; fplot('10*10^(-x)',x) title('f(x) = 10*10^-x') xlabel('rectilinear scale') ylabel('rectilinear scale') % Part (d) figure(7) x = 0:0.01:10; y = 10*10.^(-x); %Note the .^ operator semilogy(x, y) % semilogy(x, y) creates a plot using a base 10 logarithmic % scale for the y-axis and a linear scale for the x-axis. title('f(x) = 10*10.^-x') xlabel('rectilinear scale') ylabel('log scale') 6 7 Problem 4 clear clc v = 20:10:70; d = [45 80 130 185 250 330]; % Part (a) quadfn = polyfit(v,d,2); % note the 2. It is for quadratic polynomial. fprintf('\n\n Part (a) \n\n'); fprintf('\n\n The quadratic polynomial is given as:\n\n'); disp(quadfn); % Part (b) figure(8) plot(v,d,'m*') % original data hold on % drawing over the previous figure without erasing it quadfnval = polyval(quadfn, v); plot(v, quadfnval); legend('Original Data','Quadratic Polynomial') hold off Part (a) The quadratic polynomial is given as: 0.0509 1.1054 2.3571 8 Problem 5 clear clc x = 0:.01:1; % x was chosen by trial and error m = -2:1:2; fx(1,:) = 10.^(m(1)*x); % a loop here would work nicely, but this is for the next class fx(2,:) = 10.^(m(2)*x); fx(3,:) = 10.^(m(3)*x); fx(4,:) = 10.^(m(4)*x); fx(5,:) = 10.^(m(5)*x); figure(9) plot(x,fx(1,:),'r',x,fx(2,:),'b',x,fx(3,:),'c',x,fx(4,:),'m',x,fx(5,:),'y') axis([0 1 0 4]) % choose scale of axis such that graph shape and key properties can be viewed. legend('m = -2', 'm = -1', 'm = 0', 'm = 1', 'm = 2') % Answer to part b - from graph - none disp('There is no m for which fx passes through the origin') There is no m for which fx passes through the origin 9 Part (c) x = 0:.01:4; % x was chosen by trial and error m = [-0.5 0 0.5 1 2]; y1 = x.^m(1); y2 = x.^m(2); y3 = x.^m(3); y4 = x.^m(4); y5 = x.^m(5); figure(10) plot(x,y1,'r',x,y2,'b',x,y3,'c',x,y4,'m',x,y5,'y') legend('m=-0.5','m=0','m=0.5','m=1','m=2') axis([0 4 0 4]) %Part d % observing the graph, answer is for m = 0.5, m = 1, m= 2 disp(' For m = 0.5, 1, and 2, f(x) passes through origin') For m = 0.5, 1, and 2, f(x) passes through origin 10 Published with MATLAB® R2015a 11 W2 SYST 221: Systems Modeling Laboratory Problem Set - Submission via Blackboard by Monday, Feb 08, 1:30 pm. - Submit a script file or a published version of it. - Use the file name convention: LastNameFirstName_W2 - Problems in blue are for classroom practice. Problem 1 Create the two matrices: and Multiply the two matrices using the element wise operator. Problem 2 Create the matrix: Construct B matrix to be the inverse of A.
Verify that A*B = I Problem 3 (2 points) Consider the following system of linear equations: 6y – 2z + 4x = 8 2x + 8y + 2z = 4 10z + 6x + 3y= 10 (1)Write the set of equations in matrix form, i.e. CX = D, and solve for the vector X (2)Write the set of equations in matrix form i.e. XE = F, and solve for the vector X Solving the above will help you understand: The difference between the right division (/) and the left division (\) operations Matrix dimensions and the meaning of translating a system of equations to matrix form (3)Solve the system of equations for values of variables x, y, and z, using the solve function. Problem 4 (2 points) Create a vector X with 8 elements, where the first element is 1, the last element is 15, and the spacing between elements is 2. (1)For each element of X, compute (use element wise operations to do this) (2)For each element, display a sentence of the form:
When the x-value is __, then the y-value is __
Note: Each sentence must be printed on a new line. The sign of the computed function value must be displayed. Problem 5 Use the fplot command to plot the function: f(x)= 0.01x − 0.03x + 0.4x – 2x – 6 x + 5 in the domain −4 ≤ x ≤ 6. Problem 6 (2 points) (1)Plot the function: 3 f(x) = 3x − 25x + 10 and its derivative, both on the same plot, for − 2 ≤ x ≤ 4 (2)Plot the function with a solid line, and the derivative with a dashed line. Add a legend and label the axes. Create text boxes on the plot, identifying the function, and its derivative (use the gtext command). Problem 7 The position x(t) and velocity v(t) as a function of time of a particle are given by: x(t) = 0.4t − 2t − 5t +13
(1)Plot the position and velocity as a function of time for
0 ≤ t ≤ 10s. (2)Use the subplot command to make the two plots on the same page, with the plot of the position on the top, the velocity at the bottom. (3)Label the axes appropriately with the correct units. Use a font size of 14. Formatting must be done in the script file. (4)Give each of the subplots a title in boldface. Use a font size of 14. Formatting must be done in the script file. Problem 8 (2 points) The graph of the function f (x) = ax + bx + cx + d passes through the points (-2 ,3), (-1 , 2), (0, 3), and (1, 6). Determine the constants a, b, c, and
d. Problem 9 (2 points) The growth in population of a certain colony of insects is modeled by the equation P = P e , where P 0 is the population at time t, P0is the population at t = 0, and r is the yearly growth rate. Assume that the initial population is 50 million and it doubles in 20 years. (1)Calculate the yearly rate of growth r (2)Calculate the population 5, 10, and 15 years from the initial time. The output should be displayed in two columns: the number of years from initial time and the corresponding population. SYST 221:S YSTEMS M ODELING L ABORATORY
NTRODUCTION TO MATLAB(MAT RIXLAB ORATORY) The basic data element in MATLAB is a Matrix (or array) MATLAB contains tools to solve common problems, and toolboxes designed to solve specific problems (such as signal processing, optimization, control systems etc.) The Command Window is MATLAB’s main window. Other extensively used
windows are the Figure window, Editor window, and Help window. There are 8
different windows in MATLAB. To type in a command, place cursor next to the command prompt (>>). Recall a previously typed command using the upward arrow key. Several commands may be typed in the same line (by typing a comma between the commands). The commands are executed from left to right. MATLAB Default Desktop I. Basic Symbols and Commands 1. The semicolon ( ; ) When a command is typed and the enter key is pressed, the command is executed, and displayed in the Command Window. If a semicolon ( ; ) is typed at the end of a command, the output of the command is not displayed. 2. The Percentage Symbol ( % ) When the percentage symbol % is typed at the beginning of a line, the line is designated as a comment, and the line is not executed. 3. The clc Command Typing the command clc next to the command prompt, and hitting enter, clears the display in the Command Window. However, the memory is not cleared, and previously typed commands may be recalled using the upward arrow key. Week 1 Page 1 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III II. Arithmetic Operations with Scalars 1. MATLAB as a Calculator a. Precedence Similar to using a calculator, there is an order of precedence in command execution: Examples of Precedence >> 8 + 3*5 ans = 23 >> 8 + (3*5) ans = 23 >> (8 + 3)*5 ans = 55 >> 4^2128/4*2 ans = 0 >> 4^212 8/(4*2) ans = 3 b. Display Formats MATLAB’s default display format is called short. It is fixed-point with 4 decimal digits. The display format can be changed using the format command. The most frequently used format types in engineering are short, short e, and bank. Example: >> format bank For other available formats, and for more details on each display format, type the command help format in the Command Window. Week 1 Page 2 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III c. Elementary Arithmetic Operations and Built-In Functions 1) Functions have a name and an argument in parentheses, i.e. function(x) Square root - sqrt(x) Exponential - exp(x) Absolute value - abs(x) Natural logarithm (to the base e) - log(x) Base 10 logarithm - log10(x) Factorial - factorial(x) 2) Trigonometric functions: angle x must be in radians sin(x) cos(x) tan(x) cot(x) 3) Rounding functions – round, fix, ceil, floor, rem, sign 2. Defining Scalar Variables A variable is a combination of letters (and digits) that is assigned a numerical value. It is a memory assignment. a. The Assignment Operator The = sign is the assignment operator.
Syntax: Variable_name = <numerical value or computable expression> Example >> x = 27^1/3 + 32^0.2 A note on variables: Variables may be used in computing expressions and assigning values to new variables. Week 1 Page 3 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III An existing variable can be overwritten with a new numeric value. Once a variable is defined, it can be used as an argument in functions. Variable names can be 63 characters long (varies with the version of MATLAB). It can contain letters, digits, and the underscore character. It must begin with a letter. MATLAB is case sensitive. Avoid using the names of built-in functions as variable names (such as sqrt, cos).
If you do, the function will become unavailable for use. >> % This is a comment. >> x = 2+3 % So is this. x = 5 b. Predefined Variables c. Strings and String Variables A string is an array of characters. Entered by typing the characters within single quotes. If the string itself contains a single quote, you need to type 2 single quotes. Mainly used to display text messages, in formatting commands of plots, and as
input arguments of some functions. >> A = 'This is a string' A = This is a string d. Some Commands for Managing Variables
Week 1 Page 4 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III III. Arrays and Array Operations An array is a list of numbers arranged in rows and/or columns. The simplest array is a one-dimensional row or column. Arrays are used to store information and data as in a table. In engineering applications, one-dimensional arrays frequently represent vectors, and two-dimensional arrays often represent matrices. String arrays consisting of characters are also possible. In MATLAB, a vector or array is created by assigning the elements of the vector to a variable. Each element can be a number, expression involving predefined variables, or functions. 1. Ways to Create a Vector 1) When data is directly known or given a. Use spaces or commas to enter row elements b. Use semicolons to generate a column vector 2) Using the colon ( : ) symbol If the first element and the last element are known, and the spacing between the elements is constant, then you can use: variable_name = [m:q:n] or variable_name = m:q:n 3) When the first term, last term, and number of terms are known, use: variable_name = linspace(xi,xf,n) – MATLAB determines the correct spacing >> % To create a row vector, separate the elements by spaces or commas. >> p = [3,7,9] p = 3 7 9 >> % To create a column vector, separate the elements by semicolons. >> q = [3;7;9] q = 3 7 9 >> % Try the following: >> r = q’ r = 3 7 9 >> % Try the following (without the semicolon at the end) >> x = 0:2:8; >> x = 0:2:9; >> x = 0:8; >> y = linspace(5,8,31); Week 1 Page 5 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III 2. Ways to Create a Matrix A matrix with ‘m rows and ‘n’ columns has a dimension m x n. For example, the following matrix A has 4 rows and 3 columns. Vectors are special cases of matrices having one row or one column. 1) The elements that are entered can be numbers or mathematical expressions. 2) All rows must have the same number of elements. 3) If an element is zero, it must be entered as such. 4) If the matrix is small you can type it row by row, separating the elements in a given row with spaces or commas and separating the rows with semicolons. Example >> A = [2,4,10;16,3,7]; Creates the following matrix: 5) Remember, spaces or commas separate elements in different columns, whereas semicolons separate elements in different rows. a. Creating a Matrix from Vectors Suppose a = [1,3,5] and b = [7,9,11] (row vectors). Observer the resulting matrices/vectors in the following session: >> c = [a b] c = 1 3 5 7 9 11 >> D = [a;b] D = 1 3 5 7 9 11 b. Matrices with Special Values Typing zeros(n) creates an n × n matrix of zeros, whereas typing zeros(m,n) creates an ???? × ???? matrix of zeros. The syntax of the ones command is the same, except that it creates arrays filled with ones. eye(n) – is used for creating an identity matrix. The transpose of a vector or array is obtained using the single quote ( ‘ ) Week 1 Page 6 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III Some notes about variables in MATLAB: There is no need to define the size of the array before the elements are assigned. All variables in MATLAB are arrays (scalar/vector/matrix) Once a variable exists, the type and size can be changed - by adding or deleting elements (more on how to do this, later) 3. Addressing Arrays a. Vectors th Let ve be a vector of size 1 x 6. To access the k element in it, use >> ve(k) You can reassign specific elements of the array. You can use the elements of an array in mathematical expressions. b. Matrices 1) Matrices are addressed by their row number and column number. I.e. A(1, 3) 2) Just like for vectors, single elements can be used like variables in mathematical expressions and functions Using a Colon The colon operator selects individual elements, rows, columns, or ''subarrays'' of arrays. Here are some examples: v(2:5) represents the second through fifth elements; that is v(2), v(3), v(4), v(5). A(:,3) denotes all the elements in the third column of the matrix A. A(:,2:5) denotes all the elements in the second through fifth columns of A. A(2:3,1:3) denotes all the elements in the second and third rows that are also in the first through third columns. v = A(:) creates a column vector v consisting of all the columns of A stacked from first to last. A(end,:) denotes the last row in A, and A(:,end) denotes the last column. c. Adding Elements to Existing Arrays >> % Assigning values to additional elements. >> DF = 1:4; >> DF(5:10) = 10:5:35; >> DF DF = 1 2 3 4 10 15 20 25 30 35 Week 1 Page 7 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III >> % Appending existing variables >> RE = [3 81 24]; >> GT = 4:3:16; >> KNH = [RE GT] KNH = 3 81 24 4 7 10 13 16 Adding to Matrices >> E = [1 2 3; 4 5 6; 7 8 9]; >> K = eye(3); >> G = [E K] G = 1 2 3 1 0 0 4 5 6 0 1 0 7 8 9 0 0 1 >> G(2,4) = 2 % Direct Assignment G = 1 2 3 1 0 0 4 5 6 2 1 0 7 8 9 0 0 1 d. Deleting Elements from Existing Arrays Let kt be a 1????10 vector >> kt(3:6) = [] Let mtr be a 3????5 matrix >> mtr(:,2:4) = [] 4. Built-In Functions for Handling Arrays The length(A)command gives the number of elements in the vector A. The length(A)command gives the largest value of m or n if A is an m × n matrix. size(A) returns a row vector [m n]. Try the following yourself: Let v be a vector >> B = diag(v) Let A be a matrix >> vec = diag(A) Week 1 Page 8 of 9 Adapted and modified from Amos Gilat, Dr. Costa, and Dr. Palm III Recommended Online Resources Documentation at The following is a good source of useful information on Matlab fundamentals. https://www.mathworks.com/help/matlab/getting-started-with-matlab.html Week 1 Topics (o

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### 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'

## Why people love StudySoup

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "I used the money I made selling my notes & study guides to pay for spring break in Olympia, Washington...which was Sweet!"

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.