Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***** Can you please write code that i can copy and paste into matlab because I

ID: 3887725 • Letter: #

Question

***** Can you please write code that i can copy and paste into matlab because I dont know how to use it at all and have this assignment due. Thanks! ******

MATLAB Like many other programming software, Matlab can call already written programs (or m-files) and use them in the current running program. In the following problem you will create this type of m-file called a function and use it within another program. The basic layout of a user-written function is as follows: Function outputs = name of fun ction(inputs) Here is placed the code that manipulates the" inputs" data to result in the "outputs" where, name of function is the name used to call this specific function is an external code inputs are the data from the external code that is manipulated outputs are the data sent to the external code after manipulation The code should be saved in a file named name of function.m See help fiunction for more information on this command. name of See help fiunction for mone n a

Explanation / Answer

As shown in the above question,

I have created a function named unit step which takes
input arguments as time (t)
Outputs as u.

Here for unitstep function the values of unitstep fucnion is 1 for all time is greater than zero.
so
u=1 for u>=0
u=0 for u<0

The below code satisfies the given requirement as follows:-

Q1:-

unitstep.m:-
--------------
function u = unitstep(t)
u = t>=0;
end

unit.m:-
---------
t = (-1:0.01:1)';
u = unitstep(t)


Q2:-

The below code satisfies the given requirement for quesion 2 to plot the graph

Here we use the function named "unitstep" created in the question one.

unitstep function is generally having amplitude of 1 for all t greater than zero and have amplitude of zero for all t lessthan zero.

so to get the given graph we need to subtract the below two signals:

1) left-shift of unitstep fucnion by 5 units i.e u(t+5)
2) left-shift of unitstep fucnion by 2 units i.e u(t+2)

so the given graph is combination of

u(t+5)-u(t+2) this is 1 for -5<=t<=-2

t^2 for -2<=t<=0

cos(2*pi*t) for 0<=t<=4

2*u(t) for 4<=t<=5

u(t) for 5<=t<=10

Matlab Program:-

Q2.m:-
-------
fplot(@(t) (unitstep(t+5) - unitstep(t+2)),[-5 -2],'b')
hold on
fplot(@(t) t.^2,[-2 0],'b')
hold on
fplot(@(t) cos(2*pi*t),[0 4],'b')
hold on
fplot(@(t) 2*u(t),[4 5],'b')
hold on
fplot(@(t) u(t),[5 10],'b')
hold off
grid on