Plot the equation y=(2x^2-3x+7)/(x-3)(x+1) using a function called cs151sp18exam
ID: 3721611 • Letter: P
Question
Plot the equation y=(2x^2-3x+7)/(x-3)(x+1) using a function called cs151sp18exam3a.m that accepts one input argument and has one output argument. The input argument is a matrix of the x values and the output argument is a matrix of the y values that are calculated using this equation. Since the denominator contains values that cause the denominator to go to zero, you must check to see if any of the x values are 3 or -1. If either of these values is in the x values matrix, then your function should display an error and not do the calculation.Explanation / Answer
%function file
function y=cs151sp18exam3a(x)
if any(x==3) || any(x==-1)
error('Do not include 3 and -1 in input!!')
else
y=(1*x.^2-3*x+7)./((x-3).*(x+1));
end
%%script file
x=-10:.1:-1.1;
y=cs151sp18exam3a(x);
plot(x,y)
x=-.9:.1:2.9;
y=cs151sp18exam3a(x);
hold on
plot(x,y);
x=3.1:.1:10;
y=cs151sp18exam3a(x);
hold on
plot(x,y);