Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For **Matlab** I need help creating a piecewise function, with the same format as provided, please try to complete it with as many notes as

For **Matlab**

I need help creating a piecewise function, with the same format as provided, please try to complete it with as many notes as possible. (does not need a driver and title I will take care of that, the bottom was provided by my teacher)

function project_6_abc()

% PROJECT_6_ABC project_6_abc() creates a function that models a piecewise function

% Date:

% to write a sub function called getData()

% Then call it here. The function will return all of the inputs.

% Call getFunction() twice - once for f(x) and a second time for g(x)

% Do not write two getFunction functions. Use the same one twice

% Plot piecewise function - need to replace the plotFunction(f, g, a, b, minT, maxT);

end

function h = H(t)

% HEAVISIDE H(t) is the tradition form for the Heaviside function. It is passed a single input value t. If t >= 0 it returns one otherwise it returns zero.

%

% You can move the step of the Heaviside function by entering the horizontal translation. ie. to have it switch to one at a instead of at 0 you would call H(t-a). To turn the function off switch the 1 and 0 - thus at a you would code (1 - H(t - a))

%

end

function f = piecewiseFunction(f, g, a, b, t)

% PIECEWISEFUNCTION piecewiseFunction evaluates the piecewise function at time t. It is passed five paramaters; f and g are the anonymous functions that form the piecewise function, a is the time at which f begins, and b is the time at which f is stopped and g begins. t is the input value for the time at which the function is to be evaluated.

%

% Evaluate the piecewise function using calls to the Heaviside function

% Note: The first piecewise function must be f(t - a) and the second

% g(t - b)

end

function plotFunction(f, g, a, b, minVal, maxVal)

% PLOTFUNCTION plotFunction(fun, minVal, maxVal) plots a function

% between the values t = minVal and t = maxVal. It requires three input parameters; f and g are the functions that will make up the piecewise function, minVal is the starting value and maxVal is the ending value.

% Updated: 30 May 2018

%

% Create a vector of input values

t = linspace(minVal, maxVal, 500);

% Plot the step function curve

plot(t, piecewiseFunction(f, g, a, b, t), '-b'); % Blue, solid line

hold on

% needed if a second plot is to be graphed so that the first plot is

% not replaced

% always reset the flag for hold

hold off

% Show the grid.

grid on

% Add labels

xlabel('time');

ylabel('Value');

title('Piecewise Function');

end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions