- if ea eps | i= maxit : this is not Matlab syntax, there's no comparison of the values
- Your function doesn't terminate with an end block
- You are using , instead of ; to terminate lines
can you solve this problem
조회 수: 1 (최근 30일)
이전 댓글 표시
I solved this problem but the file didn't run, the codes in the editor are:
function [s,ea,i]=SqRoot(a,eps,maxit)
i = 0;
s = a/2;
ea = 100;
while(1)
sold = s;
s= (s+a/s)/2;
i = i+1;
if s ~= 0, ea=abs((s - sold)/s)*100; end
if ea <= eps | i>= maxit, break, end
end
댓글 수: 5
Walter Roberson
2016년 1월 27일
a_arg = rand();
eps_arg = randn() / 10^8;
maxit_arg = randi([10,500]);
[s_ans, ea_ans, i_ans] = Student(a_arg, eps_arg, maxit_arg)
답변 (1개)
Star Strider
2016년 1월 26일
Your code runs for me, and produces the correct result:
a = 50; % Argument
maxit = 100; % Argument
i = 0;
s = a/2;
ea = 100;
while(1)
sold = s;
s= (s+a/s)/2;
i = i+1;
if s ~= 0, ea=abs((s - sold)/s)*100; end
if ea <= eps || i>= maxit, break, end
end
What problems are you having with it?
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!