y = (2x^2)/((x-2)(x-6) in matlab

To evaluate y = (2x^2)/((x-2)(x-6)) in MATLAB, we first need to define a function that represents the polynomial.

main.m
function y = mypolynomial(x)
  y = (2 .* x.^2) ./ ((x - 2) .* (x - 6));
end
76 chars
4 lines

This code defines a function named mypolynomial that takes a scalar or array input x and returns the corresponding value(s) of y.

To evaluate the polynomial at specific values of x, we can simply call the function with the input value(s):

main.m
x = 0:0.1:10;
y = mypolynomial(x);
plot(x,y);
46 chars
4 lines

This code will evaluate the polynomial at 101 evenly-spaced values of x between 0 and 10, and plot the corresponding values of y.

gistlibby LogSnag