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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Harry
am 25 Jan. 2022
Bearbeitet: Harry
am 25 Jan. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Denoising and Compression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!