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 Window
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Problemi Consider the plecewise function sit) defined as follows: -(+2 when -2sts2 0.5 elsewhere s(t)- Write...
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
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