I cannot get my function to solve quadratic equations to work. Can anyone help?
3 views (last 30 days)
Show older comments
function [disc, quadRoots] = Q1_15024248(a,b,c);
disc = b^2-(4*a*c);
if disc < 0
disp('NaN')
elseif D==0
quadRoots = -b/2*a
else
x1 = -b + sqrt(disc)/(2*a);
x2 = -b - sqrt(disc)/(2*a);
quadRoots = [x1,x2];
end
end
it leaves me with the error message:
function [disc, quadRoots] = Q1_15024248(1,4,4);
↑
Error: Function definitions are not permitted in this context.
0 Comments
Accepted Answer
James Tursa
on 25 Jan 2018
Put your function code in a file called Q1_15024248.m somewhere on the MATLAB path (e.g., your working directory).
More Answers (0)
See Also
Categories
Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!