- 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 ビュー (過去 30 日間)
古いコメントを表示
%% 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 件のコメント
回答 (2 件)
Gaurav Aggarwal
2020 年 7 月 2 日
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 件のコメント
Cris LaPierre
2020 年 7 月 2 日
編集済み: Cris LaPierre
2020 年 7 月 2 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Scope Variables and Generate Names についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!