Question

In: Mechanical Engineering

Use a for loop to plot the function given in Problem 16 over the interval -2 ≤ x ≤ 6. Properly label

Use a for loop to plot the function given in Problem 16 over the interval -2 ≤ x ≤ 6. Properly label the plot. The variable y represents height in kilometers, and the variable x represents time in seconds.

Solutions

Expert Solution

Program plan:

• To write a matlab code that using for loop to plot the piece wise function in the conditional statement.

 

Program:

%**********************************************************

%A matlab code to plot the piece wise function using the

%for loop for the given range of ‘x’.

%**********************************************************

%Program Code

%Declaration of the array

x=[-2:0.1:6];

for (i=1:length(x)) %Initialization of for loop

if (x(i)<-1) %Conditional statement

%Computes the value

y(i)=exp(x(i)+1);

elseif (x(i)>=-1)&(x(i)<5) %Conditional statement

%computes the value

y(i)=2+cos(pi*x(i));

else %Default statement

%Computes the value

y(i)=10*(x(i)-5)+1;

end %End of conditional statement

end %End of for loop

%Plotting the piece wise function

plot (x,y);

%Assigns text to x-axis

xlabel(\'Time in seconds\');

%Assigns text to y-axis

ylabel(\'Height in kilometers\');

 

Output:

 


Related Solutions

Plot the function y = 10(1 = e-x/4) over the interval 0 ≤ x ≤ xmax, using a while loop to
Plot the function y = 10(1 = e-x/4) over the interval 0 ≤ x ≤ xmax, using a while loop to determine the value of xmax such that y(xmax) = 9.8.Properly label the plot. The variable y represents force in newtons, and the variable x represents time in seconds.
Plot the function y = 10 *(1 -exp(x/4)) over the interval 0 <x < xmax ,...
Plot the function y = 10 *(1 -exp(x/4)) over the interval 0 <x < xmax , using a for loop to determine the value of xmax such that y(xmax)=9.8. Properly label the plot. variable y is represents force in Newtons , and x represents time in second.
Expand the function, f(x) = x, defined over the interval 0 <x <2, in terms of:...
Expand the function, f(x) = x, defined over the interval 0 <x <2, in terms of: A Fourier sine series, using an odd extension of f(x) and A Fourier cosine series, using an even extension of f(x)
Use MATLAB to plot the functions u = 2 log10(60x + 1) and υ = 3 cos(6x) over the interval 0 ≤ x ≤ 2.
Use MATLAB to plot the functions u = 2 log10(60x + 1) and υ = 3 cos(6x) over the interval 0 ≤ x ≤ 2. Properly label the plot and each curve. The variables u and represent speed in miles per hour; the variable x represents distance in miles.
Random variable X is uniformly distributed over the interval [2, b]. Given: P { |X –...
Random variable X is uniformly distributed over the interval [2, b]. Given: P { |X – 4 | > 4} = 0. 8. a) Find P { 0 < X < 5}
Sketch the linearized Bode plots of system function given below. Ensure to properly label the graph....
Sketch the linearized Bode plots of system function given below. Ensure to properly label the graph. H(s) = 10^9 (s + 100)(s + 1000) / (s^2 + 15000s + 100 × 10^6)(s + 100 × 10^3)
Among 16 electrical components exactly 4 are known not to function properly. If 6 components are...
Among 16 electrical components exactly 4 are known not to function properly. If 6 components are randomly selected, find the following probabilities: (i) The probability that all selected components function properly. (ii) The probability that exactly 3 are defective. (iii) The probability that at least 1 component is defective.
Find the lengths of the functions of x over the given interval.
Find the lengths of the functions of x over the given interval.
The average value of a function f over the interval [-2,3] is -6, and the average...
The average value of a function f over the interval [-2,3] is -6, and the average value of f over the interval [3,5] is 20. What is the average value of f over the interval [-2,5]?
MATLAB Question Write a script to plot the function 'x times sine-squared of x' over a...
MATLAB Question Write a script to plot the function 'x times sine-squared of x' over a user-specified interval. It should prompt the user to enter the starting and stopping values of x, perform the calculation, and plot the result. Test the script using start/stop values 28 and 42.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT