Question

1. Write a Matlab function, piecewise (), that will calculate and return the value of the function f(x) defined by: 0<rS3 3<s
0 0
Add a comment Improve this question Transcribed image text
Answer #1

piecewise.m

function y=piecewise(x)
if(x<=0)
y=1;
elseif(x>0 && x<=3)
y=exp(-x);
elseif(x>3 && x<=5)
y=-cos(3*x);
elseif(x>5)
y=2*sin(x);
end
end

plotpiecewise.m

x=[];
for i=-3:0.01:8
x=[x,i];
end
y=[];
for i=-3:0.01:8
y=[y,piecewise(i)];
end
plot(x,y);
xlabel('x')
ylabel('y')
title('y=piecewise(x)')

Output Plot:

5 05 -0.5 - 1.5

Add a comment
Know the answer?
Add Answer to:
1. Write a Matlab function, piecewise (), that will calculate and return the value of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a MATLAB script to plot the function of f(x) given by: Write a MATLAB script...

    Write a MATLAB script to plot the function of f(x) given by: Write a MATLAB script to plot the function of f(x) given by: f(x) = integral x^2 - pi^2/4 x > pi/2 8 * cos x -pi/2 lessthanorequalto x lessthanorequalto pi/2 pi^2/4 - x^2 x < -pi/2

  • Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

    Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels. The user-defined function should 1. Receive a single x value as input. 2....

  • Write as a MatLab function P5: For X=0 ~ 2π with intervals of π/100 use the...

    Write as a MatLab function P5: For X=0 ~ 2π with intervals of π/100 use the following equations Y4=sin(X), Y5=sin(X-0.25), Y6=sin (X-1.5), Y7=sin(X-0.85), Y8=sin(X)sin(X+0.75) a. Plot Y4, Y5 and Y6 in the same plot. Add title, labels, legend. Plot them with different colors and line styles b. Plot Y4, Y5, Y6 and Y7 as subplots. Add title, labels. Plot them with different colors and line styles c. Plot Y4 and Y8 in the same plot using the hold on/off. Add...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • ON MATLAB, CREATE THOSE OUTPUTS WITH DIFFERENT VALUES. BE SURE U HAVE TO CHANGE NUMBERS, COLORS,...

    ON MATLAB, CREATE THOSE OUTPUTS WITH DIFFERENT VALUES. BE SURE U HAVE TO CHANGE NUMBERS, COLORS, SHAPES AND LTNE WEIGHTs... AND SHOW YOUR OUTPUT RESULTS AS WELL... the code:: % About Graphs x = 0: pi/40: 4*pi; figure, plot(x, sin(x)) figure, plot([1 1 2 3 3], [0 2 3 2 0]), axis([0 4 0 4]) % for easy plotting: figure, ezplot('tan(x)') % for plotting two graphs on the same axes % it allows to have independent y-axis labels on the...

  • Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following...

    Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following math function with x the input argument and y the output y(x)=0.8x4-13x2-5x The function should work for x being a scalar or a vector. Write a script file named PBTask4pl.m to a) Use the function to calculate y(3) and y(5) and display the results in command window b) Use the function to make a plot of the function y(x) for -5:5: x 5:5. Label...

  • answer 4, 5, 6, 7 using matlab Homework 10 1. Write the correct first-line syntax for...

    answer 4, 5, 6, 7 using matlab Homework 10 1. Write the correct first-line syntax for a user defined function that is named Feynman and has input variables q and e, and outputs L and M. (Comment out of this line). 2. Using zeros, ones, and eye commands write the one line syntax to create the following matrix: 00000 01100 01010 01001 3. Write the syntax for the user defined function that calculates the surface area and volume of a...

  • Using Matlab; Please show written program to execute and instructions to create plot: 1. Create a...

    Using Matlab; Please show written program to execute and instructions to create plot: 1. Create a vector of x values from 0 to 20 pi, with an increment of pi/100. y=x sin (x) and z= x cos (x) a) create a figure window with two subplots. In first subplot create an x versus y plot and in the second subplot create an y versus z plot. b) create a polar plot of x and y. Add title and labels to...

  • Q The graph of a piecewise-defined function is given. Write a definition for the function that...

    Q The graph of a piecewise-defined function is given. Write a definition for the function that best describes this graph. a (1,1) -7 100) if xs f(x) = if 0<xs

  • 1. Write a short MATLAB script or function (m-file) that generates the functions (t)eu(t) for a =...

    Only calculate manually 1. Write a short MATLAB script or function (m-file) that generates the functions (t)eu(t) for a = 0.1. Plot the value of x(t). Since the e-af almost attenuates to 0 after 5T, where T1. So make your time vector from 0 to 5T would be enough to capture the signal.) 2. Using the definition of the FT (1), manually calculate the FT of the given functions in previous exercise 0O x(t)e 3. Plot the absolute values and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT