Question

2. A. Write a MATLAB code to plot the function ?(?) = 4 − ? ^2...

2. A. Write a MATLAB code to plot the function ?(?) = 4 − ? ^2 * ? ^−3? for the time range 0 ≤ ? ≤ 3 seconds. Plot the function using the following two methods: I. Use MATLAB’s colon operator and vector operations. II. Use iterations (for-loop) and scalar operations. B. Let ? = −3, 1, 5, … ,21. I. Find the summation of the elements of ? that are greater than the 4 ?ℎelement and less than or equal to the last element. Store the output in sum_x. II. Rearrange the elements of ? in descending order and store the new vector as x_des.

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

PLEASE REFER BEOW CODE

close all
clear all
clc

%A)plot the function ?(?) = 4 − t ^2 * t ^−3? for the time range 0 ≤ t ≤ 3 seconds.
%I) Use MATLAB’s colon operator and vector operations.
t = 0:0.1:3; %create vector using colon operator
f = 4 - t.^2 .* exp(-3 * t); %given func
%plot function
figure();
plot(t,f);
xlabel('time (t)');
ylabel('f(t)');
title('t vs f(t)');

%II) Use iterations (for-loop) and scalar operations.
%loop through each of t value and calculate f(t)
for i = 1:length(t)
f(i) = 4 - ((t(i) * t(i)) * exp(-3 * t(i)));
end

%plot function
figure();
plot(t,f);
xlabel('time (t)');
ylabel('f(t)');
title('t vs f(t)');

%B)
%I)I. Find the summation of the elements of ? that are greater than the
%4 ?ℎelement and less than or equal to the last element.
x = -3:4:21
sum_x = sum(x(5:end))

%II) Rearrange the elements of ? in descending order and store the new vector as x_des.
x_des = flip(x)

PLEASE REFER BELOW OUTPUT

Add a comment
Know the answer?
Add Answer to:
2. A. Write a MATLAB code to plot the function ?(?) = 4 − ? ^2...
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
  • *MATLAB CODE* 3)Write a function 'mydsort' that sorts a vector in descending order (using a loop,...

    *MATLAB CODE* 3)Write a function 'mydsort' that sorts a vector in descending order (using a loop, not the built-in sort function). 4)write a function that will receive a vector and will return two index vectors: one for ascending order and one for descending order. Check the function by writing a script that will call the function and then use the index vectors to print the original vector in ascending and descending order. **Please make sure they work. I have found...

  • please write the code on matlab   using for loop Also practice using for loops to combine...

    please write the code on matlab   using for loop Also practice using for loops to combine two vectors with the same number of elements. do in-between iterations one before the last iteration will have w/index=(last element-1)) = 4x(index=(last_element-1)) - 2(2) last iteration windex=last element)= 4*x[index=last element) - z(1) you need to figure out how to the change in index for vector z within the for loop.

  • Matlab code assistance - task 1 and 6 I think I am right and just need...

    Matlab code assistance - task 1 and 6 I think I am right and just need to be pointed in the right direction if I should change anything %% Task 1 % create the 3 row vectors shown in Ex 8 using 3 different approaches Ex 8 = using the colon operator and also the linspace function, create the following row vectors -5 -4 -3 -2 -1 5 7 9 8 6 4 % 1. list the values explicitly (square...

  • Please use MatLab and comment code. Problem 2 Write a MATI AB user-defined function y-M?SotxType): x...

    Please use MatLab and comment code. Problem 2 Write a MATI AB user-defined function y-M?SotxType): x is a vector containing numbers. and Type can be 'Ascending' or Descending'. This function should sort the given vector x in the ascending or descending order based on the user's request and return the desired vector as the output. Do not use MATLAB built-in function sort. Hint: When you call this function you need to use for Ascending or Descending since they are strings.

  • [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a...

    [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...

  • matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name...

    matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name the function [max_value, max_index] - LASTNAMES matrix max (x), where input argument x is a vector or matrix (not a scalar), and the outputs are the maximum value(s) and indexes of the maximum value(s) of the mput x. Do not use MATLAB functions max() or find(). Use loops and if branches to determine the maximum elements of matrix. Check for correct number and valid...

  • What would the function look like in MATLAB? Write a function called mysort that takes a...

    What would the function look like in MATLAB? Write a function called mysort that takes a 3-element vector as its sole arguments. It uses if statements, possibly nested, to return a 3-element vector with its elements in non-decreasing order, i.e., the first element in the returned vector equals the smallest element of the input vector and the last element equals the largest element in the input vector. NOTE: Your function should not use any built-in functions, e.g., sort, min, max,...

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

  • Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces...

    Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces to grams for 0 to 16 ounces, in 1-ounce increments. Present output in a table; label columns appropriately. 2. A Fibonacci sequence is composed of elements created by adding the previous 2 elements. The simplest Fibonacci sequence starts with 1, 1 and proceeds as follows: 1,1,2,3,5,8… Element 3 is the sum of elements 1 and 2 (1+1=2) Element 4 is the sum of elements...

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