Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

65Size
Leading solution size is 14.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
% Courtesy of Aurelien Queffurust
filetext = fileread('quadratic.m');
assert(isempty(strfind(filetext, '*')),'sign * forbidden')
assert(isempty(strfind(filetext, 'mtimes')),'mtimes forbidden')
assert(isempty(strfind(filetext, 'cross')),'cross forbidden')
assert(isempty(strfind(filetext, 'prod')),'prod forbidden')
assert(isempty(strfind(filetext, 'cumprod')))
assert(isempty(strfind(filetext, 'times')))
assert(isempty(strfind(filetext, 'mldivide')))
assert(isempty(strfind(filetext, 'mrdivide')))
assert(isempty(strfind(filetext, '/')),'/ forbidden')
assert(isempty(strfind(filetext, '\')))
assert(isempty(strfind(filetext, '-')))
assert(isempty(strfind(filetext, '^')),'^ forbidden')
assert(isempty(strfind(filetext, 'dot')))
assert(isempty(strfind(filetext, '''')),'string forbidden')
assert(isempty(strfind(filetext, 'num2str')))
assert(isempty(strfind(filetext, 'int2str')))
assert(isempty(strfind(filetext, 'dec2bin')))
assert(isempty(strfind(filetext, 'roots')))

                    
2
Pass
 
%%
a=1;b=1;c=1;
rad=sqrt(b*b-4*a*c);
xe(1)=(-b+rad)/(2*a);
xe(2)=(-b-rad)/(2*a)
xq = quadratic(a,b,c)
assert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))
xe =
  Column 1
                       -0.5 +     0.866025403784439i
  Column 2
                       -0.5 -     0.866025403784439i
xq =
  Column 1
                       -0.5 +     0.866025403784438i
  Column 2
                       -0.5 -     0.866025403784438i
3
Pass
 
%%
a=1;b=4;c=1;
rad=sqrt(b*b-4*a*c);
xe(1)=(-b+rad)/(2*a);
xe(2)=(-b-rad)/(2*a)
xq = quadratic(a,b,c)
assert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))
xe =
        -0.267949192431123         -3.73205080756888
xq =
  Column 1
         -0.267949192431123 +  3.28143120844893e-17i
  Column 2
          -3.73205080756888 +  4.57044407574452e-16i
4
Pass
 
%%
a=1;b=4;c=1;
a=a+rand
rad=sqrt(b*b-4*a*c);
xe(1)=(-b+rad)/(2*a);
xe(2)=(-b-rad)/(2*a)
xq = quadratic(a,b,c)
assert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))
a =
          1.18093812973462
xe =
        -0.271812533477663         -3.11532511521429
xq =
  Column 1
         -0.271812533477663 +  3.32874349091553e-17i
  Column 2
          -3.11532511521429 +  3.81517293065054e-16i