Problemi Consider the plecewise function sit) defined as follows: -(+2 when -2st
ID: 2294011 • Letter: P
Question
Problemi Consider the plecewise function sit) defined as follows: -(+2 when -2sts2 0.5 elsewhere s(t)- Write a MATLAB user-defined function called aystfun.n that has one input argument to, and two output arguments: s0 and vsO. Your function must satisfy all the following requirements: 1. Your function must calculate and return the vector so - s(t0) for any supplied numerical vector to. We assume that the function is always called with a vector t0 whose elements are all in [-4,4]. 2. The variable vs0 must be calculated as shown below, if and only if, the function is called with two output arguments 1 when at least one element of s0 is strictly greater than 0.5 0 when none of the elements of s0 is strictly greater than 0.5 This is what you need to do for Assignment 07. Write the user-defined function and save it in file named mystfun.m Test the function by calling it with two output arguments s0 and vsO and input argument: to-[15, 0,-1, 2.5); 1. 2. 3. Report the testing results obtained in Command WindowExplanation / Answer
function [s0, vs0]=mystfun(t0)
s0=[]; % initiating a null vector to store data
for i=1:length(t0);
t=t0(i);
if t>=-2 && t<=2; % verifying wether tis in the range [-2 2] or not
s0(i)=t^2+2; % if YES s0=t^2+2
else s0(i)=0.5; % if NO s0=0.5
end
end
if nargout==2 % checking the number of output arguments of this function
G=s0(s0>0.5);% checking wether any element of s0 is greater than 0.5
if isempty(G)
vs0=0; % if NO, vs0=0
else vs0=1; % if YES, vs0=1
end
end
% results
>> t0=[1.5,0,-1,2.5];
>> [s0,vs0]=mystfun(t0)
s0 =
4.2500 2.0000 3.0000 0.5000
vs0 =
1
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.