%% Display and Solve Quadratic Equation
% Define a string that represents a quadratic formula with the coefficients a, b, and c.

syms a b c k
symstr = "a*x^2 + b*x + c";

% Display the quadratic formula, replacing a with k.

displayFormula(symstr,a,k)

% Display the quadratic formula again, replacing a, b, and c with 2, 3, and -1, respectively.

displayFormula(symstr,[a b c],[2 3 -1])

% To solve the quadratic equation, convert the string into a symbolic expression using str2sym. Use solve to find the zeros of the quadratic equation.

f = str2sym(symstr);
sol = solve(f)

% Use subs to replace a, b, and c in the solution with 2, 3, and -1, respectively.

solValues = subs(sol,[a b c],[2 3 -1])

%
% Copyright 2019 The MathWorks, Inc.