g Write a user-defined MATLAB function for the following math function: y ( x )=(−.2 x 3 +7 x 2 )e −.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

Respuesta :

Answer:

Go to explaination for the step by step answer.

Explanation:

a)Code

function[y]=operation(x) % this function takes x as input and returns y as output

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

end

% call this function in command widow by typing operation(value of x) like shown in figure in the first attachment.

b. write a code of above function in one script window and save the code with same name as name of function that is name of script should be saved as operation.Now copy paste the below code in new script window and run the code

clc

clear all

x=-2:.1:6

n=length(x)

for i=1:1:n

a=x(i)

y(i)=operation(a)

end

plot(y,x)

xlabel('X')

ylabel('Y')

Please kindly check attachment for pictorial answers that supports the code.

Ver imagen kendrich
Ver imagen kendrich