Question

matlab code needed urgent

media%2F67d%2F67d61c7e-2390-4bba-a8a2-59

matlab code needed urgent

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a)

% create a vector for time

t = [ -pi : 0.01 : pi ];

% create a vector of same length as t to store f(t)

f = [ 1 : length(t) ];

for i = 1 : length(t)

   

    % if -pi <= t < 0

    if t(i) < 0 && t(i) >= -pi

       

        f(i) = exp(t(i));

       

  % if 0 <= t < pi

    else

       

       f(i) = exp(-t(i));

       

    end

   

end

% set the label of axis

ylabel('f(t)');

xlabel('t');

grid on

hold

% plot the graph

plot( t , f );

Sample Output

(b)

% create a vector for time

t = [ 0 : 0.01 : 2 * pi ];

% create a vector of same length as t to store f(t)

f = [ 1 : length(t) ];

for i = 1 : length(t)

   

    % if 0 <= t < pi/2

    if t(i) < pi && t(i) >= 0

       

        f(i) = -1;

      

    % if pi / 2 <= t < 3 * pi / 2

    elseif t(i) < 3 * pi / 2 && t(i) >= pi / 2

       

        f(i) = 1;

       

    % if 3 * pi / 2 <= t < 2 * pi

    else

       

       f(i) = -1;

       

    end

   

end

% set the label of axis

ylabel('f(t)');

xlabel('t');

grid on

hold

% plot the graph

plot( t , f , 'r');

Sample Output

Add a comment
Know the answer?
Add Answer to:
matlab code needed urgent
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