- call RQ16_19(a,b,c)
- calculate x1 and x2 for a,b,c
- call RQ16_19(10,5,3)
- calculate x1 and x2 for 10,5,3
- call RQ16_19(10,5,3)
- Repeats.
Out of memory. The likely cause is an infinite recursion within the program.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%% Variables
% Input
% a
% b the corresponding coefficients in the quadratic equation
% c
% Output
% x1 positive root of the equation
% x2 negative root of the equation
% Write your entire function code below here (Including header)
function [x1, x2] = RQ16_19(a,b,c) % The order of input variables should be a, b, and then c
x1 = (-b+sqrt(b^2-4*a*c))/(2*a);
x2 = (-b-sqrt(b^2-4*a*c))/(2*a);
RQ16_19(10,5,3)
end
I am trying to run this code in Matlab Grader and it keeps gigiving me that 'Out of memory' error? Can someone please help?
0 commentaires
Réponses (2)
Gaurav Aggarwal
le 2 Juil 2020
Hi Sean,
RQ16_19(10,5,3)
The above function call is causing the problem. Consider one call to RQ16_19 with some parameters say a,b,c. The following chain of instructions will happen,
You see the infinite recursion here?
As per my understanding, you are trying to find roots of a quadratic equation, you wouldn't need the function call within the function. Just remove the above line of code, and then RQ16_19 should be able to work perfectly fine.
Hope this helps. Thanks.
0 commentaires
Cris LaPierre
le 2 Juil 2020
Modifié(e) : Cris LaPierre
le 2 Juil 2020
Do you want to be calling your function recursively? If so, try adding a semicolon at the end of your "RQ16_19(10,5,3)" line of code.
If your code prints too many lines to the screen, it can fill up the available memory in MATLAB Grader.
However, as Gaurav mentions, if you are just trying to solve the quadratic equation, you do not need to have your function call itself recursively.
0 commentaires
Voir également
Catégories
En savoir plus sur Scope Variables and Generate Names 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!