ME 101: Computational Tools for Engineers Spring 2016 Quiz 8 Date: March 23, 201
ID: 3596587 • Letter: M
Question
ME 101: Computational Tools for Engineers Spring 2016 Quiz 8 Date: March 23, 2016 Problem 1:Consider the following criteria with if statement For values ofx , y = cos(x) y =-1 7, a) Create a single input-output function that can accept a scalar. b) Test your function by tryingthese values: x =-1, x-/3 and x : 4 c) Display the results of part b in a proper text format using fprintf d) Plot the function usingfror for x = [-, 2]. Problem 2: The height of a rocket (in meters) is given by the following expressions in terms of time (in seconds). h 2.1 3t2-0.00 13t' + 0.000034t4.751 a) Use find to determine when the rocket hits the ground, and find the corresponding time. Hint the value of height will be positive for all values until the rocket hits the ground. b) Determine the maximum height and the corresponding time. c) Plot height versus time. Hint: remove the negative height if happens to appear. d) Add a text to the plot stating the information obtained from part a and part b.Explanation / Answer
Hi,
These are two separate questions, please post other one as a separate question, as its againt chegg policy to answere more than one in single answer.
1.
here is the full copyable code with comments to help you understand.
function[result]=demo(x)%function to calculate the value of function
if (x <0) %if input <0
result =1;
elseif (x>0 )&&(x<=pi())%if >0 and less than pi
result = cos( x );
else %if >pi
result = -1;
end
fprintf('the value of fuction at -1 is %d',demo(-1))%using fprintf to print in proper format
fprintf('the value of fuction at 4 is %d',demo(4))
fprintf('the value of fuction at /3 is %d',demo(pi()/3))
f = @(x) (1)*(x<0)+(cos(x))*(x>0)*(x<=pi()) +(-1)*(x>pi()) ;%creating anonymous function as per the given if criteria
fplot(f, [-pi(), 2*pi()])
Thumbsup if this was helpful, otherwise let me know in comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.