Effacer les filtres
Effacer les filtres

quadroot and quadratic equation

3 vues (au cours des 30 derniers jours)
Zelda Luxenburry
Zelda Luxenburry le 3 Fév 2012
I need some help with this problem...MATLAB gives me an error when I use "quadroot".
Use the if...elseif...else...end flow control structure to write a function m-file that solves for the real roots x1, x2 of the quadratic equation y=ax2+bx+c. Your function should be defined as follows:
function x = quadroot(a,b,c)
in which the input arguments a,b,c are the coefficients of the quadratic equation (assume a~=0) and the output argument x is a vector containing the two roots x(1) and x(2). In the case of complex roots, your function should assign the real portion of the roots to x(1) and x(2). Name your submitted file quadroot.m. You may assume that the values of the input arguments passed to your function are double precision real numbers.
  2 commentaires
Walter Roberson
Walter Roberson le 3 Fév 2012
What error do you see when you use "quadroot" ?
Zelda Luxenburry
Zelda Luxenburry le 5 Fév 2012
"Function definitions are not permitted in this context" or "not enough input arguments."

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Fév 2012
"Function definitions are not permitted in this context" happens if you try to put a function in the same file as a script. Functions can only go in the same file as other functions. If you have test code to invoke the function, then that test code should either be a function itself or should be in a different file.

Plus de réponses (0)

Catégories

En savoir plus sur Quadratic Programming and Cone Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by