i have a function and i need to find the output of the last value. y(n)=1/2*(y(n-1)+A^2/y(n-1)) 0<=n<=N-1 (N=30 A=4),When i run it says output arguments not assignet.
조회 수: 1 (최근 30일)
이전 댓글 표시
function res = my_matlab_function(A,N)
y(1)=1/2*(3+(A^2/3));
y(2)=1/2*(y(1)+(A^2/y(1)));
for n=2:(N-1)
y(n)=1/2*(y(n-1)+A^2/y(n-1));
end
댓글 수: 0
답변 (1개)
Harry
2022년 1월 25일
편집: Harry
2022년 1월 25일
Hi Tasos,
you have not assigned y to res whihc is your function output. I corrected your code in the following way:
function res = my_matlab_function(A,N) % res is te function output
y(1)=1/2*(3+(A^2/3));
y(2)=1/2*(y(1)+(A^2/y(1)));
for n=2:(N-1)
y(n)=1/2*(y(n-1)+A^2/y(n-1));
end
res = y; % Assign it to the res
end
and then you can extract the last value by res(end). I hope it works for you.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!