answer to a quadratic function

1 Ansicht (letzte 30 Tage)
Agatha E. Johnson
Agatha E. Johnson am 30 Sep. 2020
Kommentiert: Matt J am 30 Sep. 2020
Hi
how do I get both of my solution in a quadratic function? I only have the answer for x1

Antworten (1)

Matt J
Matt J am 30 Sep. 2020
For example,
>> roots([1,5,2]) %roots of x^2+5*x+2
ans =
-4.5616
-0.4384
  2 Kommentare
Agatha E. Johnson
Agatha E. Johnson am 30 Sep. 2020
Hm, thanks for the answer. But when I do that the answer is not right.
this is the function, and how i didi it
  1. y = x^2+ x 12,
function [x1, x2] = myquadratic(a,b,c)
a = 1;
b = 1;
c = -12;
X = sqrt(b^2-4*a*c);
Y = 2*a;
x1 = (-b + X) / Y;
x2 = (-b - X) / Y;
here I only get
ans= 3
but i would like to get
ans=-4 as well
Matt J
Matt J am 30 Sep. 2020
In all likelihood, that is because you did not call the function with 2 output arguments.
K>> [x1,x2]=myquadratic()
x1 =
3
x2 =
-4

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by