write a function for y(x)=(-0.2x^3+7x^2)e^-0.3x in matlab

Here's the Matlab function to evaluate the given equation:

main.m
function result = y(x)
% Evaluate y(x) = (-0.2x^3 + 7x^2) * e^(-0.3x)

result = (-0.2 .* x .^ 3 + 7 .* x .^ 2) .* exp(-0.3 .* x);

end
135 chars
7 lines

To use the function, simply call it with the desired x value(s):

main.m
x = 0:0.1:10;     % Define range of x values
y_values = y(x);  % Evaluate y(x) for each x in the range

plot(x, y_values);  % Plot the result of y(x) vs x
ylabel('y(x)'); xlabel('x');
184 chars
6 lines

This will generate a plot of y(x) vs x for the given range of x values.

gistlibby LogSnag