Homework Help Question & Answers

1. Write a Matlab function, piecewise (), that will calculate and return the value of the...


1. Write a Matlab function, piecewise (), that will calculate and return the value of the function f(x) defined by: 0<rS3 3<s
1. Write a Matlab function, piecewise (), that will calculate and return the value of the function f(x) defined by: 0
0 0
Next > < Previous
ReportAnswer #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

Know the answer?
Add Answer of:
1. Write a Matlab function, piecewise (), that will calculate and return the value of the...
Your Answer: Your Name: What's your source?
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
  • 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...

  • Basic MATLAB : Writing a MATLAB code

    Write a MATLAB code to create a graph of two functions on a single plot across an x range of 0 to 2pi :f(x) = sin(2x) - dashed black lineg(x) = 2cos(2x) - green solid lineLabel both the axes ( x and y) and title (use the 'title' command ) the graph " Plot of f(x)=sin(2x) and its derivative. Include a legend that distinguishes the twolines.The number of points that are used to create the lines should be sufficient to...

  • Write a C code to calculate the following piecewise function using switch. Assume user enters x (...

    Help needed in c program ! Thannx Write a C code to calculate the following piecewise function using switch. Assume user enters x (a real number) tan(x +1) 10 f(x) =,x = 0 x <0 Write a C code to calculate the following piecewise function using switch. Assume user enters x (a real number) tan(x +1) 10 f(x) =,x = 0 x

  • 3. Use Laplace transforms to solve the following initial value problems. Write the solution (t) f...

    3. Use Laplace transforms to solve the following initial value problems. Write the solution (t) for t20 as a simplified piecewise defined function. (a) z', + 2x' + 2x-f(t), x(0-0, z'(0)-i, where f(t)-〈0 otherwise. (b) z', +x-f(t), x(0) 0, z'(0)=1, where t/2 if 0 t< 6, 3 ift26 f(t) 3. Use Laplace transforms to solve the following initial value problems. Write the solution (t) for t20 as a simplified piecewise defined function. (a) z', + 2x' + 2x-f(t), x(0-0, z'(0)-i,...

  • Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that seme...

    Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that semester Enter your grades (letters): AABBC (input) Your GPA is 3.2 output) b) Write a Matlab user defined function to that takes a letter grade and return a numeric grade as shown in the table below. Any other value should give an error message (Invalid Grade). You function name should be Letter2Grade Use the following information to calculate...

  • i need the required MATLAB script to solve this question please. 1) (20 points) Calculate the following for the function f(x)2x3 a. Calculate the derivative of the function by hand. Write a MATLA...

    i need the required MATLAB script to solve this question please. 1) (20 points) Calculate the following for the function f(x)2x3 a. Calculate the derivative of the function by hand. Write a MATLAB function that calculates the derivative 05. of this function and calculate the derivative at x b. Develop an M- to evaluate the cetered finite-difference approximation (use equation below), at x-o.5. Assume that h 0.1. c Repeat part (b) for the second-order forward and backward differences. Again Assume...

  • A periodic signal, x(t) is shown below. A = 10, T-4 sec. -T Write a MATLAB script to plot the sig...

    A periodic signal, x(t) is shown below. A = 10, T-4 sec. -T Write a MATLAB script to plot the signal, using enough points to get a smooth curve. Compute the Fourier series coefficients for the signal (if you can find them in the text, that is ok). Plot the single-sided or double-sided spectra for each signal. Include enough frequencies in the plots to adequately represent the frequency content of the signals. Plot partial sums of the Fourier series for...

  • Write a script for Matlab that calculates the position of a ball being dropped from a height of...

    Write a script for Matlab that calculates the position of a ball being dropped from a height of 10 meters with an initial velocity of 0 as a function of time. Havethe script accept the value of time from the user using the input function. Then display the result in the command window.Now the position of the ball as a function of time is known calculate the position of the ball for a set of time points using a ‘for...

  • Problem 2: A periodic signalxit) is shown below A =10, T-4 sec. -T Write a MATLAB script to plot ...

    Problem 2: A periodic signalxit) is shown below A =10, T-4 sec. -T Write a MATLAB script to plot the signal, using enough points to get a smooth curve. Compute the Fourier series coefficients for the signal (if you can find them in the text, that is ok). Plot the single-sided or double-sided spectra for each signal. Include enough frequencies in the plots to adequately represent the frequency content of the signals. Plot partial sums of the Fourier series for...

  • b) (2.5 marks) Write a Matlab user defined function that takes the letter grades (i.e. AABBC) as input and returns...

    b) (2.5 marks) Write a Matlab user defined function that takes the letter grades (i.e. AABBC) as input and returns if the student entitled to the honor list or not. The student is considered in the honor s f he or she satisfies the following three conditions: a. An average GPA of 3.5 and above and b. At least two classes with A mark and e. no class with a mark less than C (i.e. no D or F) The...

Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.