MATLAB: I am trying to write a program to solve a quadratic equation using loops and braces. see the images for the exact problem and the attempt

matlab loop structures

Here is the exact problem:
Here is my attempt:
The answers I get are: y1=5.750000e+000 and y2=-238. However, I'm not convinced by this because I should be getting more than 2 answers, shouldn't I…? i.e. for=-9:0.5:9 generates a 1×37 array. Many thanks if anyone can spot the problems!

Best Answer

t = -9:.5:9;
n = numel(t);
out = zeros(n,1);
for jj = 1:n
if t(jj) < 0
out(jj) = 3*t(jj)^2 + 5;
else
out(jj) = -3*t(jj)^2 + 5;
end
end
or
t = (-9:.5:9)';
out = -3*sign(t).*t.^2 + 5;