Create two vectors of length 10 of your choice and label


Assignment

1. Revisiting MATLAB anonymous functions and basic logic operations.

a) Use both "polyval" and an anonymous function to calculate the following:

i. 4??4 + 2??2 + ?? - 19 at x = 1,5,10,15
ii. ??2 - 5 at x = 1,3,12,20
iii. 5??3 + 36?? + 8 at x = -5,-1,3,8

b) Using basic logic operators, answer the following questions using MATLAB

i. Create two vectors of length 10 of your choice, and label them x and z.
ii. Show, element by element, where x and z are equal.
iii. Show, element by element, where x is greater than z.
iv. Show, element by element, where x is less than or equal to z.
v. Find the elements where x is greater than z.
vi. Find the elements where z is less than or equal to x.
vii. Replace the elements in (vi) with values 10 times their original value in a single operation.

2. User-defined input-output and logical statements.

a) Consider the following function:
?? = e3x^2+(4/5)x + 36?? + 1

It is desired that this function be evaluated for a variety of user-defined values of x. Create a script file/segment of code that will allow the user to neatly and professionally input a scalar OR vector value of x. Evaluate the function at 3 user- selected points as well as a single user-defined vector input. Display the result using disp(). Be sure to include some output text in addition to displaying the function evaluation result.

b) Consider the following function:

?? (??, ??) = x2 + xy - 36?? + xe4x^2 + 9

Allow the user to input values for both x and y as scalars. Only allow the function to evaluate if the value of x is less than or equal to y. If the function is evaluated, display the value of x and y as well as the function evaluation result using a single instruction. If not, show an appropriate error message to the user and do not allow the function to be evaluated. Evaluate your code at the following points:

i. x = 5, y = 5
ii. x = 0.25, y = e3x
iii. x = 0.2, y = √(?? - 0.01)
iv. x = 1, y = 5

c) Consider the multi-variable function given by:

?? (??, ??, ??) = [√(5z2 + xy3) + 5] / (?? + ?? + ??)

allow the user to input scalar values for x,y, and z and include logic that will stop the script and display an error message if the function is singular or would result in an imaginary number for a provided set of x,y,z. If the function is allowed to evaluate, display the entered values of x,y, and z as well as the value of the function using a single instruction. Otherwise, display and error message. Evaluate at the following points (x,y,z):

i. (4,13,15)
ii. (8,-12,0.1)
iii. (0,0,0)
iv. (5,10,15)

d) Consider the case where the input to a program can be either a scalar, vector, a matrix or a combination of these. Write a program that can add, subtract, multiply or divide the input variables. Note that the division portion is not valid for matrices (we use inverses instead) - you will need to incorporate this in your code. Your program should prompt the user for the type of operation to be performed, to enter the two variables and display the results neatly (using fprintf) or the appropriate error message if the code fails to execute. Test your code using at least 7 different combinations of x and y, allowing each to be scalars, matrices of various shapes (not only square) and vectors.

e) Recall, from homework #3, the equation of motion given by:

?? = 1/2 gt2

where g = 9.81 and time is defined in seconds. Allow the user to input the total time in which he/she would like to know the position of the object. Fix your step-size at 0.1 seconds and start your vector at zero (ending at the value of "total time", which should be input as a scalar). Additionally, create a selection structure that allows the user to select which graph to plot - either the position, velocity or acceleration vs. the time vector you create. Plot the position, velocity and acceleration in 3 separate code executions for a total time of 5 seconds.

3. Working with flowcharts and code documentation.

a) Create a flowchart for the following:

i. Question 2(a)
ii. Question 2(b)
iii. Question 2(c)
iv. Question 2(e)

Solution Preview :

Prepared by a verified Expert
MATLAB Programming: Create two vectors of length 10 of your choice and label
Reference No:- TGS01672992

Now Priced at $60 (50% Discount)

Recommended (90%)

Rated (4.3/5)