Question

# Using MATLAB Write a user-defined MATLAB function for the following math function: y(x)= (-0.2x^3 + 7x^2)e^-0.3x...

Using MATLAB

Write a user-defined MATLAB function for the following math function:

y(x)= (-0.2x^3 + 7x^2)e^-0.3x

The input to the function is x and the output is y. Write the function such that x can be a vector (use element-by-element operations).

(a) Use the function to calculate y(-1.5) and y(5).

(b) Use the function to make a plot of the function y(x) for -2 ≤ x ≤ 6.

The first step is to define the function for the given equation

function y=fun(x)
y=(-0.2*x.^3+7*x^2).*exp(-0.3*x);
end

a) Then you have to give the input of x as given in the question -1.5 and 5 respectively and you will gett the answer as

>> fun(-1.5)

ans =2 5.7595

>>fun(5)

ans = 33.4695

b) Then to plot the function we use the code

x=linspace(-2, 6, 500);

y=fun(x);

plot(x,y)

xlabel('x')

ylabel('y')

Which gives us the following graph

#### Earn Coins

Coins can be redeemed for fabulous gifts.